我现在有这个nginx日志输出。
log_format json_logs escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent"'
'}';
access_log /var/log/nginx/access.log json_logs;但是,当Fluentd输出和收集时,它是以时间戳和标准输出作为前缀的。
例如..。
2022-06-18T19:05:15.014296769Z stdout F {\"time_local\":\"18/Jun/2022:19:05:15 +0000\",\"remote_addr\":\"10.106.0.5\",\"remote_user\":\"\",\"request\":\"GET / HTTP/1.1\",\"status\": \"304\",\"body_bytes_sent\":\"0\",\"request_time\":\"0.000\",\"http_referrer\":\"\",\"htt p_user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.99 Safari/537.36\"}我不能正确地解析它,我暂时将它设置为
<source>
@type tail
path /var/log/containers/*nginx*.log
pos_file /var/log/nginx.log.pos
tag nginx.access
<parse>
@type nginx
expression ^(?<somenginxstuff>.*)$
time_key logtime
time_format %d/%b/%Y:%H:%M:%S.%z
</parse>
</source>把它全部倒入弹性/基巴纳,这样我就可以检查输出了。
问题是--做这件事的最好/最简单的方法是什么?我想这是很常见的用法吧?
此外,我已经看到了插件的提到,我使用的是基本的fluent/fluentd-kubernetes-daemonset:v1.14.6-debian-elasticsearch7-1.0映像。我如何添加这些(如果它们有帮助)?
事先非常感谢
发布于 2022-06-19 19:22:12
最后,我用json解析它,然后过滤字段以像json一样解析,如下所示。
接下来的日志输出..。
2022-06-18T19:05:15.014296769Z stdout F {\"time_local\":\"18/Jun/2022:19:05:15 +0000\",\"remote_addr\":\"10.106.0.5\",\"remote_user\":\"\",\"request\":\"GET / HTTP/1.1\",\"status\": \"304\",\"body_bytes_sent\":\"0\",\"request_time\":\"0.000\",\"http_referrer\":\"\",\"htt p_user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.99 Safari/537.36\"}而这个配置
<source>
@type tail
path /var/log/containers/*nginx*.log
pos_file /var/log/nginx.log.pos
tag nginx.access
<parse>
@type regexp
expression ^(?<timestamp>[^ ]*) [^ ]*[ ][^ ] (?<data>.*).*$
</parse>
</source>
<filter nginx.access>
@type parser
key_name data
<parse>
@type json
</parse>
</filter>https://stackoverflow.com/questions/72672036
复制相似问题