您的位置:首页 > 运维架构 > Docker

使用fluentd监控docker日志时加入容器id

2017-02-15 15:38 1096 查看
td-agent.conf配置文件内容如下:

<source>
type tail
read_from_head true
path /var/lib/docker/containers/*/*-json.log
pos_file /var/log/fluentd-docker.pos
time_format %Y-%m-%dT%H:%M:%S
tag docker.*
format json
</source>
# Using filter to add container IDs to each event
<filter docker.var.lib.docker.containers.*.*.log>
type record_transformer
<record>
container_id ${tag_parts[5]}
</record>
</filter>

<match docker.var.lib.docker.containers.*.*.log>
type elasticsearch
logstash_format true
host "#{ENV['ES_PORT_9200_TCP_ADDR']}" # dynamically configured to use Docker's link feature
port 9200
flush_interval 5s
</match>


1.tag_parts[]数组中的内容就是filter之后的标记以点分隔

2.
<source>
中的
tag docker.*
中的 *指:

*可以作为一个占位符扩展到实际的文件路径,用’.’代替’/’。比如:
path /path/to/file

tag foo.*


相当于

path /path/to/file

foo.path.to.file
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: