我有一种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
Run Code Online (Sandbox Code Playgroud)
在Kibana中可见的字段如下图所示:
在对这种类型的日志建立索引之后,是否可以从中提取字段?
流利的收集器配置有以下可处理所有容器的源,因此由于来自不同容器的输出差异很大,因此在此阶段无法强制执行格式:
<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>
Run Code Online (Sandbox Code Playgroud)
在理想情况下,我想用“ log”字段中的元字段来丰富上面屏幕快照中的可见字段,例如“ host”,“ req”,“ status”等。