[英]fluentd regex pattern not match error for NGINX logs
我已經設置流利的解析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進行了測試,並將輸出用於配置。
我不確定調試此錯誤該從哪里走。 任何幫助都將被申請
你的表達是正確的。 問題是您正在使用不贊成使用的format參數。 相反,您將需要使用解析器插件,並且內置了nginx解析器,您可以在其中設置表達式。 下面將是您更新的fluent.conf,它可以很好地解析您的輸入。
<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
<parse>
@type nginx
expression /(?<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
</parse>
@log_level debug
</source>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.