Skip to content

Instantly share code, notes, and snippets.

@mariotacke
Created March 7, 2017 04:36
Show Gist options
  • Save mariotacke/88053be5be5ef87b7544ece220f41af4 to your computer and use it in GitHub Desktop.
Save mariotacke/88053be5be5ef87b7544ece220f41af4 to your computer and use it in GitHub Desktop.

Revisions

  1. mariotacke created this gist Mar 7, 2017.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    Pattern file: `/etc/logstash/patterns/nginx`
    Logstash shipper: `/etc/logstash/conf.d/shipper.conf`

    Nginx http log module:
    http://nginx.org/en/docs/http/ngx_http_log_module.html
    3 changes: 3 additions & 0 deletions nginx-default-log-format
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    log_format combined '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent"';
    1 change: 1 addition & 0 deletions nginx.pattern
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    NGINX_ACCESS %{IPORHOST:remote_addr} - %{USERNAME:remote_user} \[%{HTTPDATE:time_local}\] \"%{DATA:request}\" %{INT:status} %{NUMBER:bytes_sent} \"%{DATA:http_referer}\" \"%{DATA:http_user_agent}\"
    31 changes: 31 additions & 0 deletions shipper.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    input {
    file {
    type => "nginx"
    start_position => "beginning"
    path => [ "/var/log/nginx/*.log" ]
    }
    }

    filter {
    if [type] == "nginx" {
    grok {
    patterns_dir => "/etc/logstash/patterns"
    match => { "message" => "%{NGINX_ACCESS}" }
    remove_tag => [ "_grokparsefailure" ]
    add_tag => [ "nginx_access" ]
    }

    geoip {
    source => "remote_addr"
    }
    }
    }

    output {
    redis {
    host => "<your redis host>"
    data_type => "list"
    key => "logstash"
    codec => json
    }
    }