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. boolalpha

    /* 功能: 把bool值显示为true或false */ #include<iostream> using namespace std; int main() { char str1[] ...

  2. php 使用GD库上传图片以及创建缩略图

    php 使用GD库上传图片以及创建缩略图   GD库是PHP进行图象操作一个很强大的库. 先在php.ini里增加一行引用:extension=php_gd2.dll 重启apache.做一个测试页 ...

  3. ecshop运行超过30秒超时的限制解决办法

    ecshop运行超过30秒超时的限制解决办法 ECSHOP模板/ecshop开发中心(www.68ecshop.com) / 2014-06-04 ecshop运行超过服务器默认的设置30秒的限制时会 ...

  4. phone number is not known @w@ have no phone, and thus no phone number

    http://dev.mysql.com/doc/refman/5.7/en/problems-with-null.html B.5.4.3 Problems with NULL Values The ...

  5. 以大写字母“J”来展示位图

    '0' => '00011100001111111001100011011000001111000001111000001111000001111000001111000001111000001 ...

  6. 不绑架输入--document.getElementById("linkage_"+id_type+"_echo").value="";--联动

    <script> function w_linkage(id_type) { var selected = $("#linkage_"+id_type+"_t ...

  7. hiho42 : 骨牌覆盖问题·二

    描述 上一周我们研究了2xN的骨牌问题,这一周我们不妨加大一下难度,研究一下3xN的骨牌问题?所以我们的题目是:对于3xN的棋盘,使用1x2的骨牌去覆盖一共有多少种不同的覆盖方法呢?首先我们可以肯定, ...

  8. PureBasic—数控编辑框与调节块和进度条

    三个有关上下限问题的控件,它们也是主要控件的组成部分,分别为:SpinGadget()        数控编辑框TrackBarGadget()    调节块控件ProgressBarGadget() ...

  9. Delphi 的绘图功能[1] - PolyBezier、PolyBezierTo

    双击代码全选 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 unit Unit1; interface uses Windows, Messages, SysUtils ...

  10. 使用JSONP跨域请求数据

    下面代码,可以使用JSONP进行跨域请求数据,Insus.NET记录以下,以备忘记.