【发布时间】:2018-12-07 18:28:35
【问题描述】:
我已经设置了 fluentd 来解析 nginx 访问日志,因为我在日志中添加了一些额外的字段,我无法使用 nginx 格式。我的配置是:
<source>
@type tail
@id service_www_accesslog
path /var/log/containers/imager-nginx*.log
pos_file /var/log/imager-nginx-containers.log.pos
tag influxdb.*
read_from_head true
format /(?<host>[^ ]*) \[(?<time>[^\]]*)\] \[Cache:(?<cache>\b\w+\b)\] "(?<CSMethod>\b\w+\b) (?<CSURIStem>(?:\/[A-Za-z0-9$.+!*'(){},~:;=@#%&_\-]*)+) (?<request>.*?)" (?<SCStatus>(?:(?:(?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+)))))) (?<image_size>(?:(?:(?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+)))))) "(?<referer>.*?)" "(?<user_agent>.*?)" "(?<xforward>.*?)" (?<request_time>(?:(?:(?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+)))))) (?<upstream_response>.*?) (?<upstream_connect>.*?) (?<upstream_header>.*)/
time_format %d/%b/%Y:%H:%M:%S %z
@log_level debug
</source>
日志样本:
10.244.1.0 [07/Dec/2018:16:51:49 +0000] [Cache:MISS] "GET /10e8cd74-94ec-4652-a5c9-d5df1110b9eb/475/400/60/false/blah.jpg HTTP/1.1" 200 60435 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36" "172.23.8.123" 0.162 0.160 0.001 0.151
在流畅的输出中我得到一个错误:
2018-12-07 16:51:50 +0000 [warn]: #0 [service_www_accesslog] pattern not match: "{\"log\":\"10.244.1.0 [07/Dec/2018:16:51:49 +0000] [Cache:MISS] \\\"GET /10e8cd74-94ec-4652-a5c9-d5df1110b9eb/475/400/60/false/blah.jpg HTTP/1.1\\\" 200 60435 \\\"-\\\" \\\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36\\\" \\\"172.23.8.123\\\" 0.162 0.160 0.001 0.151\\n\",\"stream\":\"stdout\",\"time\":\"2018-12-07T16:51:49.224406444Z\"}"
我已经使用几个正则表达式测试器测试了正则表达式,它确实有正确的输出,我还使用Fluentular 进行了测试并将输出用于配置。
在调试此错误时,我不确定从哪里开始。任何帮助都会得到帮助
【问题讨论】:
-
请张贴清晰的输入样本和所需的输出。
-
@PedroLobito 不确定我应该添加哪些额外信息?有一个日志条目示例提供,我希望没有错误。