第一个小案例
第一步:编写/etc/td-agent/td-agent.conf
文件,内容如下
<source>
@type http
port 8888
bind 0.0.0.0
</source>
<match test.cycle>
@type stdout
</match>
配置文件的名词解释
source
:使用http插件,在8888端口启动一个web服务用于收集日志match
:匹配到test.cycle
标签,然后进行标准输出
# 执行如下命令
systemctl restart td-agent
tail -f /var/log/td-agent/td-agent.log
curl -i -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/test.cycle
# 会看到如下输出:
2020-07-02 08:42:16.086179077 +0000 test.cycle: {"action":"login","user":2}
第二个小案例
第一步:编写/etc/td-agent/td-agent.conf
文件,内容如下
<source>
@type http
port 8888
bind 0.0.0.0
</source>
<filter test.cycle>
@type grep
<exclude>
key action
pattern ^logout$
</exclude>
</filter>
<match test.cycle>
@type stdout
</match>
名称解释
filter:
过滤掉logout事件
systemctl restart td-agent
tail -f /var/log/td-agent/td-agent.log
curl -i -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/test.cycle
curl -i -X POST -d 'json={"action":"logout","user":2}' http://localhost:8888/test.cycle
# 结果:
2020-07-02 08:42:16.086179077 +0000 test.cycle: {"action":"login","user":2}
第三个小案例
第一步:编写/etc/td-agent/td-agent.conf文件,内容如下
<source>
@type http
bind 0.0.0.0
port 8888
@label @STAGING # 注意这里我们添加了label 会直接匹配到label
</source>
<filter test.cycle>
@type grep
<exclude>
key action
pattern ^login$
</exclude>
</filter>
<label @STAGING>
<filter test.cycle>
@type grep
<exclude>
key action
pattern ^logout$
</exclude>
</filter>
<match test.cycle>
@type stdout
</match>
</label>
名词解释
label:
会直接跳到label标签,中间的filter标签不执行
systemctl restart td-agent
tail -f /var/log/td-agent/td-agent.log
curl -i -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/test.cycle
curl -i -X POST -d 'json={"action":"logout","user":2}' http://localhost:8888/test.cycle
# 结果:
2020-07-02 08:42:16.086179077 +0000 test.cycle: {"action":"login","user":2}