【发布时间】:2017-02-20 01:12:14
【问题描述】:
我有一种 ELK 堆栈,使用 fluentd 而不是 logstash,在 Kubernetes 集群上作为 DaemonSet 运行,并将所有容器中的所有日志以 logstash 格式发送到 Elasticsearch 服务器。
在 Kubernetes 集群上运行的众多容器中,有一些是 nginx 容器,它们输出以下格式的日志:
121.29.251.188 - [16/Feb/2017:09:31:35 +0000] host="subdomain.site.com" req="GET /data/schedule/update?date=2017-03-01&type=monthly&blocked=0 HTTP/1.1" status=200 body_bytes=4433 referer="https://subdomain.site.com/schedule/2589959/edit?location=23092&return=monthly" user_agent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0" time=0.130 hostname=webapp-3188232752-ly36o
在 Kibana 中可见的字段如下图所示:
这种类型的日志被索引后是否可以提取字段?
fluentd 收集器配置了以下源,它处理所有容器,因此由于来自不同容器的输出非常不同,因此无法在此阶段强制执行格式:
<source>
type tail
path /var/log/containers/*.log
pos_file /var/log/es-containers.log.pos
time_format %Y-%m-%dT%H:%M:%S.%NZ
tag kubernetes.*
format json
read_from_head true
</source>
在理想情况下,我想用“log”字段中的元字段来丰富上面屏幕截图中可见的字段,例如“host”、“req”、“status”等。
【问题讨论】:
标签: logging kubernetes kibana elastic-stack fluentd