0. 安装、启动

安装

curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh

更新:最近貌似会安装最新版本2.3.2安装会有问题,可以手动下载td-agent-2.2.1-0.el6.x86_64.rpm,手动安装

sudo rpm -ivh td-agent-2.2.1-0.el6.x86_64.rpm

启动

/opt/td-agent/embedded/bin/ruby /usr/sbin/td-agent --log /var/log/td-agent/td-agent.log --use-v1-config --group td-agent --daemon /var/run/td-agent/td-agent.pid

1. http输入,stdout输出

例子

<source>
@type http
port
bind 0.0.0.0
</source> <match td3.**>
type stdout
</match>

请求

curl http://10.218.139.216:8888/td3 -d 'json={"hi":"abc"}'

结果(/var/log/td-agent/td-agent.log)

-- :: + td3: {"hi":"abc"}

格式:

<match td2.**>
@type mongo
host 10.218.139.216
port 27017
database db_log
collection db_col
time_format %H-%M-%S:%s #时-分-秒.毫秒
localtime #本地时间
flush_interval 10s
</match>

2. http输入,文件输出

例子

## Source descriptions
# HTTP input
# POST http://localhost:8888/<tag>?json=<json>
<source>
@type http
port
bind 0.0.0.0
</source> ## Output
# File output
# match tag=td.*.* and output to file
<match td.**>
@type file
path /home/jihite/monitor/test.log
flush_interval 10s
</match> ## match tag=td2.*.* and output to file
<match td2.**>
@type file
path /home/jihite/monitor/test_2.log
flush_interval 10s
</match>

http请求:

curl http://10.218.139.216:8888/td2 -d 'json={"hi":1}'

linux命令:

发POST请求工具:

结果查看:

--01T15::+:       td      {"hi":}

3. http输入,mongoDB输出

例子

## Source descriptions
# HTTP input
# POST http://localhost:8888/<tag>?json=<json>
<source>
@type http
port
bind 0.0.0.0
</source> ## Output
# MongoDB output
# match tag=td2.*.* and output to file
<match td2.**>
@type mongo
host 10.218.139.216
port
database db_log
collection db_col
time_key time
flush_interval 10s
</match>

请求

curl 10.218.139.216:/td2 -d 'json={"hi":"123"}'

结果查询:

> show dbs
db_log .078GB
local .078GB > use db_log
switched to db db_log > show collections
db_col
system.indexes > db.db_col.find()
{ "_id" : ObjectId("56af19dbdfb99f0f50000001"), "hi" : , "time" : ISODate("2016-02-01T08:39:47Z") }

4. python写日志

安装插件

sudo pip install fluent-logger

参考:https://github.com/fluent/fluent-logger-python

日志记录示例:

import logging
from fluent import handler custom_format = {
'host': '%(hostname)s',
'where': '%(module)s.%(funcName)s', #具体到文件、函数
'type': '%(levelname)s',
'stack_trace': '%(exc_text)s'
} logging.basicConfig(level=logging.DEBUG) l = logging.getLogger('fluent.test') h = handler.FluentHandler('python.mongo', host='10.218.139.216', port=24224)
formatter = handler.FluentRecordFormatter(custom_format)
h.setFormatter(formatter) l.addHandler(h) def funcs():
l.warning("hello")
l.error("hello error") l.info('{"from": "1", "to": "2"}')

修改td-agent.conf

<source>
@type forward
port
</source> <match python.mongo.**>
@type mongo
host 10.218.139.216
port
database db_python
collection col_python
time_key time
flush_interval 10s
</match>

Fluentd 例子的更多相关文章

  1. 使用Fluentd + MongoDB构建实时日志收集系统

    Fluentd是一个日志收集系统,它的特点在于其各部分均是可定制化的,你可以通过简单的配置,将日志收集到不同的地方. 目前开源社区已经贡献了下面一些存储插件:MongoDB, Redis, Couch ...

  2. fluentd学习笔记

    转载自http://blog.csdn.net/qq_27252133/article/details/53520416 原文https://blog.laisky.com/p/fluentd/ 最近 ...

  3. 日志收集工具 Fluentd 使用教程

    转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247499829&idx=1&sn=1f92daa88d ...

  4. Fluentd 简明教程

    转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247491814&idx=1&sn=3b0f1a3477 ...

  5. 21. Fluentd输出插件:rewrite_tag_filter用法详解

    我们在做日志处理时,往往会从多个源服务器收集日志,然后在一个(或一组)中心服务器做日志聚合分析. 源服务器上的日志可能属于同一应用类型,也可能属于不同应用类型.我们可能需要在聚合服务器上对这些不同类型 ...

  6. 18. Fluentd输出插件:out_stdout用法详解

    stdout即标准输出,out_stdout将收到的日志事件打印到标准输出. 如果Fluentd以daemon方式在后台运行,out_stdout会将事件输出到Fluentd的运行日志中. 这个插件在 ...

  7. 15. Fluentd输入插件:in_tail用法详解

    in_tail输入插件内置于Fluentd中,无需安装. 它允许fluentd从文本文件尾部读取日志事件,其行为类似linux的tail -F命令(按文件名来tail). 这几乎是最常用的一个输入插件 ...

  8. 14. Fluentd输出插件:out_forward用法详解

    out_forward是一个带缓存的输出插件,用于向其他节点转发日志事件,并支持转发节点之间的负载均衡和自动故障切换. out_forward支持至多一次和至少一次传输模式,默认为至多一次. out_ ...

  9. 12. Fluentd部署:多Workers进程模式

    介绍如何使用Fluentd的多worker模式处理高访问量的日志事件.此模式会运行多个worker进程以最大利用多核CPU. 原理 默认情况下,一个Fluentd实例会运行一个监控进程和一个工作进程. ...

随机推荐

  1. Java数组运算

    在使用Java进行程序设计的时候,当为一个long型变量赋值一个整数常量时,如果这个值超过int型数据的取值范围,程序就会出现编译错误,但是有一种情况程序不会出错的,就是将多个int型数据进行算数运算 ...

  2. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  3. php处理数组函数大全

    PHP:指示支持该函数的最早的 PHP 版本. 函数 描述 PHP array() 创建数组. 3 array_change_key_case() 返回其键均为大写或小写的数组. 4 array_ch ...

  4. Maven 创建多模块工程

    1. 创建父项目 new -->project-->maven-->maven Project,然后下一步, 进入new maven Project的Select project n ...

  5. redis缓存怎么存储对象

    2.把对象Object存储到redis中,怎么存?memcache存取对象是序列化和反序列化 使用通用的序列化.反序列化(频繁的会很消耗cpu,使用Google Protocol Buffer,将对象 ...

  6. centos时间同步方法

    centos时间同步方法 电脑软硬件应用网 45IT.COM 时间:2012-12-08 18:09 作者:李本清 新装的服务器可能设置了错误的,需要调整时区并调整时间.如下是使用NTP来从一个时间服 ...

  7. LR性能测试脚本增强与调试

    脚本增强与调试 一般来说,使用LR的Vugen录制的脚本并不能直接用于测试,需要对脚本进行各方面的增强,主要包括添加注释.关联.检查点.事务.参数化.日志输出等.下面结合刚完成的一个web项目性能测试 ...

  8. a read only variable

    SHOW VARIABLES LIKE '%FORMAT%' SET DATE_FORMAT ='%Y-%m-%d' [SQL]SET DATE_FORMAT ='%Y-%m-%d' [Err] 12 ...

  9. cookie 操作

    //创建并赋值 重新赋值也是这样操作 document.cookie="userId=828"; document.cookie="userName=hulk" ...

  10. 【Java IO】FileInputStream 和 FileOutputStream

    class FileInputStream extends  InputStream implements Closeable