Wednesday, November 15, 2017

Nginx log file proceeding in ELK - reference


https://logz.io/blog/nginx-log-analysis/

A sample NGINX access log entry:

  1. 109.65.122.142 - - [10/Nov/2015:07:06:59 +0000] "POST /kibana/elasticsearch/_msearch?timeout=30000&ignore_unavailable=true&preference=1447070343481 HTTP/1.1" 200 8352 "https://app.logz.io/kibana/index.html" "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/45.0.2454.101 Chrome/45.0.2454.101 Safari/537.36" 0.465 0.454

The Logstash configuration to parse that NGINX access log entry:

  1. grok {
  2. match => [ "message" , "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}"]
  3. overwrite => [ "message" ]
  4. }
  5.  
  6. mutate {
  7. convert => ["response", "integer"]
  8. convert => ["bytes", "integer"]
  9. convert => ["responsetime", "float"]
  10. }
  11.  
  12. geoip {
  13. source => "clientip"
  14. target => "geoip"
  15. add_tag => [ "nginx-geoip" ]
  16. }
  17.  
  18. date {
  19. match => [ "timestamp" , "dd/MMM/YYYY:HH:mm:ss Z" ]
  20. remove_field => [ "timestamp" ]
  21. }
  22.  
  23. useragent {
  24. source => "agent"
  25. }

A sample NGINX error log:

  1. 2015/11/10 06:49:59 [warn] 10#0: *557119 an upstream response is buffered to a temporary file /var/lib/nginx/proxy/4/80/0000003804 while reading upstream, client: 66.249.88.173, server: 0.0.0.0, request: "GET /kibana/index.js?_b=1273 HTTP/1.1", upstream: "http://172.17.0.30:9000/kibana/index.js?_b=1273", host: "app.logz.io", referrer: "https://app.logz.io/kibana/index.html"

The Logstash configuration to parse that NGINX error log:

  1. grok {
  2. match => [ "message" , "(?%{YEAR}[./-]%{MONTHNUM}[./-]%{MONTHDAY}[- ]%{TIME}) \[%{LOGLEVEL:severity}\] %{POSINT:pid}#%{NUMBER}: %{GREEDYDATA:errormessage}(?:, client: (?%{IP}|%{HOSTNAME}))(?:, server: %{IPORHOST:server})(?:, request: %{QS:request})?(?:, upstream: \"%{URI:upstream}\")?(?:, host: %{QS:host})?(?:, referrer: \"%{URI:referrer}\")"]
  3. overwrite => [ "message" ]
  4. }
  5.  
  6. geoip {
  7. source => "client"
  8. target => "geoip"
  9. add_tag => [ "nginx-geoip" ]
  10. }
  11.  
  12. date {
  13. match => [ "timestamp" , "YYYY/MM/dd HH:mm:ss" ]
  14. remove_field => [ "timestamp" ]
  15. }

No comments:

Post a Comment