Fluentd 例子
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 例子的更多相关文章
- 使用Fluentd + MongoDB构建实时日志收集系统
Fluentd是一个日志收集系统,它的特点在于其各部分均是可定制化的,你可以通过简单的配置,将日志收集到不同的地方. 目前开源社区已经贡献了下面一些存储插件:MongoDB, Redis, Couch ...
- fluentd学习笔记
转载自http://blog.csdn.net/qq_27252133/article/details/53520416 原文https://blog.laisky.com/p/fluentd/ 最近 ...
- 日志收集工具 Fluentd 使用教程
转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247499829&idx=1&sn=1f92daa88d ...
- Fluentd 简明教程
转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247491814&idx=1&sn=3b0f1a3477 ...
- 21. Fluentd输出插件:rewrite_tag_filter用法详解
我们在做日志处理时,往往会从多个源服务器收集日志,然后在一个(或一组)中心服务器做日志聚合分析. 源服务器上的日志可能属于同一应用类型,也可能属于不同应用类型.我们可能需要在聚合服务器上对这些不同类型 ...
- 18. Fluentd输出插件:out_stdout用法详解
stdout即标准输出,out_stdout将收到的日志事件打印到标准输出. 如果Fluentd以daemon方式在后台运行,out_stdout会将事件输出到Fluentd的运行日志中. 这个插件在 ...
- 15. Fluentd输入插件:in_tail用法详解
in_tail输入插件内置于Fluentd中,无需安装. 它允许fluentd从文本文件尾部读取日志事件,其行为类似linux的tail -F命令(按文件名来tail). 这几乎是最常用的一个输入插件 ...
- 14. Fluentd输出插件:out_forward用法详解
out_forward是一个带缓存的输出插件,用于向其他节点转发日志事件,并支持转发节点之间的负载均衡和自动故障切换. out_forward支持至多一次和至少一次传输模式,默认为至多一次. out_ ...
- 12. Fluentd部署:多Workers进程模式
介绍如何使用Fluentd的多worker模式处理高访问量的日志事件.此模式会运行多个worker进程以最大利用多核CPU. 原理 默认情况下,一个Fluentd实例会运行一个监控进程和一个工作进程. ...
随机推荐
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- hlg 2130 状压dp
基本的状压dp 需要注意的是两点之间直线最短 所以不需要进行floyd 由于把dp的memset放在了初始化0的后面de了好久的bug.. #include<stdio.h> #inclu ...
- 11. 求奇数分之一序列前N项和
求奇数分之一序列前N项和 #include <stdio.h> int main() { int denominator, i, n; double item, sum; while (s ...
- PHP 设计模式 笔记与总结(9)数据对象映射模式
[数据对象映射模式] 是将对象和数据存储映射起来,对一个对象的操作会映射为对数据存储的操作.例如在代码中 new 一个对象,使用数据对象映射模式就可以将对象的一些操作比如设置一些属性,就会自动保存到数 ...
- GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告
GDC2016[全境封锁(Tom Clancy's The Division)]对为何对应Eye Tracked System,以及各种优点的演讲报告 原文 4Gamer編集部:松本隆一 http:/ ...
- C#winfrom控件命名规范
※用红字标记的部分表示有重复出现,括号内为替代表示方案 1.标准控件 序号 控件类型简写 控件类型 1 btn Button 2 chk CheckBox 3 ckl CheckedListBox ...
- HTML: 字體設置
針對 font-family 屬性進行詳細設置, 首先我們要瞭解,字體分類: ①無襯線字體: san-serif,一般用於文章標題 ②有襯線字體: serif,一般用在段落處或者非標題部分 當我們設置 ...
- regardless of how many processors are devoted to a parallelized execution of this program
https://en.wikipedia.org/wiki/Amdah's_law Amdahl's law is often used in parallel computing to predic ...
- Android 4.2蓝牙介绍
蓝牙一词源于公元十世纪丹麦国王HaraldBlatand名字中的Blatand.Blatand的英文之意就是Blue tooth.这是因为这位让丹麦人引以为傲的国王酷爱吃蓝莓以至于牙龈都被染成蓝色.由 ...
- CDH介绍
本文引用自:Cloudera 系列2:CDH介绍http://www.aboutyun.com/thread-18379-1-1.html(出处: about云开发) CDH提供: 灵活性-存储任何类 ...