在fluentd的配置文件中,有如下的配置:
# http://<ip>:9880/myapp.access?json={"event":"data"} <source> @type http port 9880 </source> <filter myapp.**> @type stdout </filter> <filter myapp.access> @type record_transformer <record> host_param "#{Socket.gethostname}" </record> </filter> # Match events tagged with "myapp.access" and # store them to /var/log/fluent/access.%Y-%m-%d # Of course, you can control how you partition your data # with the time_slice_format option. <match myapp.access> @type stdout </match>
那么,这个filter指令中的record_transformer有什么作用呢?
<filter myapp.access> @type record_transformer <record> host_param "#{Socket.gethostname}" </record> </filter>
访问如下的http端口:
curl -i -X POST -d 'json={"action":"login","user":2}' http://localhost:9880/myapp.access
查看td-agent的日志:
# 正常产生的event 2022-11-17 21:38:14.862955192 -0500 myapp.access: {"action":"login","user":2} # 经过record_transformer这个过滤插件之后的event 2022-11-17 21:38:14.862955192 -0500 myapp.access: {"action":"login","user":2,"host_param":"centos7"}
看出来区别了吗?就是,增加了一个字段:
<record> host_param "#{Socket.gethostname}" </record>
key: host_param
value: "#{Socket.gethostname}",获取主机名。
所以,record_transformer插件的作用就是在event中增加字段或者修改字段。对event进行一个转换。
标签:插件,transformer,param,access,record,myapp,event From: https://www.cnblogs.com/chuanzhang053/p/16902480.html