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实例会运行一个监控进程和一个工作进程. ...
随机推荐
- 【iHMI43真彩液晶模块】发布新版 DEMO 软件包,版本号为 0.14
新版DEMO软件包主要在以下几个方面进行了改进: 1.改进触摸算法,使用链表注册模式:注册触摸按键后:用户只需要处理事件(event)就行了,其他都由系统完成: 2.改进systick 和 usart ...
- Apache Spark源码走读之6 -- 存储子系统分析
欢迎转载,转载请注明出处,徽沪一郎. 楔子 Spark计算速度远胜于Hadoop的原因之一就在于中间结果是缓存在内存而不是直接写入到disk,本文尝试分析Spark中存储子系统的构成,并以数据写入和数 ...
- The P4 Language Specification v1.0.2 Parser
<p4规范>解析器部分详解 p4解析器是根据有限状态机的思想来设计的. 解析器中解析的过程可以被一个解析图(parser graph)所表示,解析图中所表示的某一个状态(或者说,在P4语言 ...
- PHP OO 编程笔记
1. 类中的方法不是全局方法,可以和外部的普通方法重名,例如: <?php function time(); 则会报错:不能重新声明方法 Fatal error: Cannot redeclar ...
- swfit-pod使用
一.查询第三方版本号 pod search SDWebImage 二.项目添加pod 1.在终端打开项目路径 2.输入 pod init 生成Podfile 三.在Podfile输入需要的第三方 ...
- VR制作的规格分析
因为UE4的演示资源更丰富一些,我这边把UE4的有代表性的演示都跑了一遍,同时也通过Rift确认效果,和里面的资源制作方式. 首先,UE4是基于物理渲染的引擎,大部分都是偏向图像真实的.使用的材质 ...
- javascript Array类
Array类 toString()方法和valueOf()方法,返回特殊的字符串.该字符串是通过对每项调用toString()方法,然后用逗号把它们连接在一起构成的.例如,对具有项"red& ...
- memcached学习笔记6--浅谈memcached的机制 以及 memcached细节讨论
附:请浅谈memcached的机制 答: ①基于C/S架构,协议比较简单 c/s架构,此时memcached为服务器端,我们可以使用如PHP,c++/c等程序连接memcached服务器. memca ...
- Bootstrap页面布局16 - BS导航菜单和其响应式布局以及导航中的下拉菜单
代码: <div class='container-fluid'> <h2 class='page-header'>导航</h2> <!-- .navrbar ...
- SVN使用安装
SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什么? ...