Created
April 30, 2020 23:13
-
-
Save ihebski/3c59c4626ca79b43ecb9e02595eec746 to your computer and use it in GitHub Desktop.
logstash-7.4 config file for ngnix access.log/ error.log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| input { | |
| file { | |
| path => ["/var/log/nginx/access.log", "/var/log/nginx/error.log"] | |
| type => "nginx" | |
| } | |
| } | |
| filter { | |
| if [path] =~ "access.log" { | |
| grok { | |
| patterns_dir => "/var/log/nginx/patterns" | |
| match => { "message" => "%{NGINX_ACCESS}" } | |
| remove_tag => [ "_grokparsefailure" ] | |
| add_tag => [ "nginx_access" ] | |
| } | |
| geoip { | |
| source => "remote_addr" | |
| } | |
| } | |
| else if [path] =~ "error.log" { | |
| grok { | |
| match => { | |
| "message" => [ | |
| "(?<timestamp>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[%{DATA:err_severity}\] (%{NUMBER:pid:int}#%{NUMBER}: \*%{NUMBER}|\*%{NUMBER}) %{DATA:err_message}(?:, client: (?<client_ip>%{IP}|%{HOSTNAME}))(?:, server: %{IPORHOST:server})(?:, request: %{QS:request})?(?:, host: %{QS:client_ip})?(?:, referrer: \"%{URI:referrer})?", | |
| "%{DATESTAMP:timestamp} \[%{DATA:err_severity}\] %{GREEDYDATA:err_message}" | |
| ] | |
| } | |
| } | |
| date { | |
| match => [ "timestamp" , "yyyy/MM/dd HH:mm:ss" ] | |
| timezone => 'UTC' | |
| } | |
| } | |
| } | |
| output { | |
| elasticsearch { | |
| hosts => ["localhost:9200"] | |
| index => "ngnix" | |
| document_type => "nginx_logs" | |
| } | |
| stdout { codec => rubydebug } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nano /var/log/nginx/patternsNGINX_ACCESS %{IPORHOST:remote_addr} - %{USERNAME:remote_user} \[%{HTTPDATE:time_local}\] \"%{DATA:request}\" %{INT:status} %{NUMBER:bytes_sent} \"%{DATA:http_referer}\" \"%{DATA:http_user_agent}\"