fluentd 的使用

发布于 2022-02-27 16:08 阅读 945

td-agent 是基于 fluentd 核心功能开发,td-agent 优先考虑稳定性而不是新功能。1️⃣

Fluentd 有9种类型的插件,其中InputOutput是最常用的

InputOutput一般是成对出现的,如果要测试InputOutput可以选stdout;如果要测试OutputInput可以选in_http。这两个组合是比较直观的

输入

in_forward

#php客户端(fluent/logger)使用此源
<source>
    @type forward
    @id in_forward
    port 24224
    bind 0.0.0.0
</source>

in_http

# http://<ip>:9880/debug.test?json={"hehe":"uu"}
<source>
    @type http
    @id in_http
    port 9880
    body_size_limit 32m
    keepalive_timeout 10s
</source>

in_monitor_agent

# http://<ip>:24220/api/plugins.json
<source>
    @type monitor_agent
    @id in_monitor_agent
    bind 0.0.0.0
    port 24220
</source>

in_tail

<source>
    @type tail
    @id in_tail
    path /var/log/nginx/access.log
    pos_file /var/log/nginx/access.log.pos
    tag nginx.access
    <parse>
        @type nginx
        keep_time_key true
    </parse>
</source>

输出

copy

#输出到目录文件的同时,也输出到标准输出
<match debug.copy>
    @type copy
    <store>
        @type file
        path /var/log/fluent/myapp2
        compress gzip
        <buffer>
            timekey 1d
            timekey_use_utc true
            timekey_wait 10m
        </buffer>
    </store>

    <store>
        @type stdout
    </store>
</match>

elasticsearch

<match nginx.access>
    @type elasticsearch
    @id out_es_nginx
    host elasticsearch
    port 9200
    index_name td.${tag}
    <buffer tag>
        timekey 1m
        timekey           1d
        timekey_wait      10m
        flush_mode        interval
        flush_interval    30s
    </buffer>
</match>

file

<match debug.file>
    @type file
    #输出到此目录
    path /var/log/fluent/myapp
    compress gzip
    <buffer>
        timekey 1d
        timekey_use_utc true
        timekey_wait 10m
    </buffer>
</match>

stdout

#标准输出,如果使用的docker,使用docker logs 可以看到
<match debug.stdout>
    @type stdout
</match>

fluentd-ui

fluentd-ui是一个基于浏览器的fluentd和td-agent管理器2️⃣

我首先尝试的docker部署,即fluentdfluentd-ui是两个独立的容器。最终发现fluentd-ui内包含一个fluentd,无法链接外部的fluentd。这样fluentd-ui的意义就不大了,没有继续研究。。。

git clone git@github.com:fluent/fluentd-ui.git
#构建镜像
docker build -t registry.cn-hangzhou.aliyuncs.com/cuiw/fluentd-ui:20220301 .

参考

1️⃣ https://cloud.tencent.com/developer/article/1622211

2️⃣ https://docs.fluentd.org/deployment/fluentd-ui

https://www.cnblogs.com/fanren224/p/8457181.html

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验