regex for nginx ingress on kubernetes

668 views
Skip to first unread message

shane lee

unread,
Nov 9, 2017, 9:47:37 PM11/9/17
to Fluentd Google Group
Hi,

I am using nginx ingress on kubernetes. I have deployed fluentd daemonset using coreos example:



For nginx parser, it does not work as they have defined their own log format:


Example is here:
http://fluentular.herokuapp.com/parse?regexp=%5E%28%3F%3Cremote%3E%5B%5E+%5D*%29+%28%3F%3Chost%3E%5B%5E+%5D*%29+%28%3F%3Cuser%3E%5B%5E+%5D*%29+%5C%5B%28%3F%3Ctime%3E%5B%5E%5C%5D%5D*%29%5C%5D+%22%28%3F%3Cmethod%3E%5CS%2B%29%28%3F%3A+%2B%28%3F%3Cpath%3E%5B%5E%5C%22%5D*%29+%2B%5CS*%29%3F%22+%28%3F%3Ccode%3E%5B%5E+%5D*%29+%28%3F%3Csize%3E%5B%5E+%5D*%29%28%3F%3A+%22%28%3F%3Creferer%3E%5B%5E%5C%22%5D*%29%22+%22%28%3F%3Cagent%3E%5B%5E%5C%22%5D*%29%22%29%3F%24&input=192.168.196.97+-+%5B192.168.196.97%5D+-+redflex+%5B10%2FNov%2F2017%3A00%3A12%3A42+%2B0000%5D+%22GET+%2Fapi%2Fv1%2Flogin%2Fstatus+HTTP%2F1.1%22+200+92+%22https%3A%2F%2Fdashboard.rts.onl%2F%22+%22Mozilla%2F5.0+%28Windows+NT+6.1%3B+Win64%3B+x64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F61.0.3163.100+Safari%2F537.36%22+550+0.002+%5Bkube-system-kubernetes-dashboard-80%5D+100.112.15.1%3A9090+92+0.002+200&time_format=time_format+%25d%2F%25b%2F%25Y%3A%25H%3A%25M%3A%25S+%25z

What i would like is to add in extra filter to parse in nginx logs. Similar to below. Anyone already defined the regex for this?

<filter kube.ingress-nginx.nginx-ingress-controller>
@type parser
# Fluentd provides a few built-in formats for popular and common formats such as "apache" and "json".
format nginx
key_name log
# Retain the original "log" field after parsing out the data.
reserve_data true

# The access logs and error logs are interleaved with each other and have
# different formats, so ignore parse errors, as they're expected
suppress_parse_error_log true
</filter>


shane lee

unread,
Nov 9, 2017, 10:52:33 PM11/9/17
to Fluentd Google Group
Message has been deleted

shane lee

unread,
Nov 9, 2017, 11:43:58 PM11/9/17
to Fluentd Google Group
Added in filter but still not working:

<filter kube.ingress-nginx.nginx-ingress-controller>
@type parser
# Fluentd provides a few built-in formats for popular and common formats such as "apache" and "json".
  format /(?<remote_addr>[^ ]*) - \[(?<proxy_protocol_addr>[^ ]*)\] - (?<remote_user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<request>[^\"]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*) "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<request_length>[^ ]*) (?<request_time>[^ ]*) \[(?<proxy_upstream_name>[^ ]*)\] (?<upstream_addr>[^ ]*) (?<upstream_response_length>[^ ]*) (?<upstream_response_time>[^ ]*) (?<upstream_status>[^ ]*)/

key_name log
# Retain the original "log" field after parsing out the data.
reserve_data true

# The access logs and error logs are interleaved with each other and have
# different formats, so ignore parse errors, as they're expected
suppress_parse_error_log true
</filter>

<match kube.ingress-nginx.nginx-ingress-controller>
type stdout
</match>
Reply all
Reply to author
Forward
0 new messages