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实例会运行一个监控进程和一个工作进程. ...
随机推荐
- 课堂Scrum站立会议演示
组名:连连看 组长:张政 组员:张金生.李权.武志远 时间:2016.10.13 20:20--20:40 会议内容: 已完成的内容: 1.选定编译语言,安装软件并配置环境,完成了游戏的基本模型. ...
- Word 2013双引号的BUG
相信使用Word 2013的朋友大多碰到过这样一个双引号的bug: 问题详细描述: word2013中,打字时引号出现问题,在输入中文情况下,输入左引号为中文,输入右引号时会自动变成英文.微软自己的输 ...
- 总结android项目的基本开发步骤(转帖)
总结android项目的基本开发步骤(转帖) 做了几个android企业应用项目后,总结了项目的基本开发步骤,希望能够交流.一 应用规划: ※确定功能. ※必须的界面及界面跳转的流程. ...
- 推荐的PHP编码规范
推荐的PHP编码规范 发布时间: 2014-05-7 浏览次数:2754 分类: PHP教程 推荐的PHP编码规范 一 编辑器设置 1. 使用Tab缩进,不要使用空格 鉴于很多编辑器在保存文件时会自动 ...
- Bootstrap页面布局9 - BS列表
列表: 无序列表(列表中项目内容没有固定的顺序), 有序列表(通常使用在一组有前后顺序的内容上), 描述列表(定义解释一组词汇) 无序列表: <ul> <li>Ueditor编 ...
- Mysql 安装问题排查方法
重启了一次服务器后,使用> mysql -u root -p登陆是出现下面的错误: ERROR 2002 (HY000): Can't connect to local MySQL server ...
- 数据库主键跟外键+修改mysql的密码
update myspl.user set password=PASSWORD(设置的密码) where user='root'; 如果修改错误:先执行use mysple;再重复上面的代码. 一. ...
- 低功耗蓝牙4.0BLE编程-nrf51822开发(7)-SDP服务发现协议
SDP的全称是Service Discovery Protocol,中文是服务发现协议.SDP(服务发现协议)是蓝牙协议体系中的核心协议,是蓝牙系统重要组成部分,是所有用户模式的基础.在蓝牙系统中.客 ...
- Dlib is a modern C++ toolkit(非常全面的类库)
http://dlib.net/ http://download.csdn.net/detail/lajuedan2508/9726225 http://download.csdn.net/detai ...
- Python 汉字简体和繁体的相互转换
其实利用python实现汉字的简体和繁体相互转早有人做过,并发布到github上了,地址:https://github.com/skydark/nstools/tree/master/zhtools ...