2015-03-01 9 views
6

Sono un nuovo utente nello stack ELK. Sto usando UWSGI come mio server. Ho bisogno di analizzare i miei registri uwsgi usando Grok e poi analizzarli.Logstash Filtro Grok per i registri uwsgi

Qui è il formato dei miei log: -

[pid: 7731|app: 0|req: 357299/357299] ClientIP() {26 vars in 511 bytes} [Sun Mar 1 07:47:32 2015] GET /?file_name=123&start=0&end=30&device_id=abcd&verif_id=xyzsghg => generated 28 bytes in 1 msecs (HTTP/1.0 200) 2 headers in 79 bytes (1 switches on core 0) 

ho usato this link per generare il mio filtro, ma non ha parsing gran parte delle informazioni.

Il filtro generato dal link qui sopra è

%{SYSLOG5424SD} %{IP}() {26 vars in 511 bytes} %{SYSLOG5424SD} GET %{URIPATHPARAM} => generated 28 bytes in 1 msecs (HTTP%{URIPATHPARAM} 200) 2 headers in 79 bytes (1 switches on core 0) 

Ecco il mio file logstash-conf.

input { stdin { } } 

filter { 
    grok { 
    match => { "message" => "%{SYSLOG5424SD} %{IP}() {26 vars in 511 bytes} %{SYSLOG5424SD} GET %{URIPATHPARAM} => generated 28 bytes in 1 msecs (HTTP%{URIPATHPARAM} 200) 2 headers in 79 bytes (1 switches on core 0)" } 
    } 
    date { 
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] 
    } 
} 

output { 
    stdout { codec => rubydebug } 
} 

Al esecuzione logstash con questo file di configurazione, viene visualizzato un messaggio di errore che dice: -

{ 
     "message" => "[pid: 7731|app: 0|req: 357299/357299] ClientIP() {26 vars in 511 bytes} [Sun Mar 1 07:47:32 2015] GET /?file_name=123&start=0&end=30&device_id=abcd&verif_id=xyzsghg => generated 28 bytes in 1 msecs (HTTP/1.0 200) 2 headers in 79 bytes (1 switches on core 0)", 
     "@version" => "1", 
    "@timestamp" => "2015-03-01T07:57:02.291Z", 
      "host" => "cube26-Inspiron-3542", 
      "tags" => [ 
     [0] "_grokparsefailure" 
    ] 
} 

La data è stata formattata correttamente. Come faccio a estrarre altre informazioni dai miei ceppi, come il mio query parameters(filename, start,end, deviceid etc) e ClientIP, Response code ecc

Inoltre, non v'è alcun built-in UWSGI log parser che può essere utilizzato, come quello costruito per apache e syslog?

EDIT

ho scritto questo per conto mio, ma getta lo stesso errore:

%{SYSLOG5424SD} %{IP:client_ip}() {%{NUMBER:vars} vars in %{NUMBER:bytes} bytes} %{SYSLOGTIMESTAMP:date} %{WORD:method} %{URIPATHPARAM:request} => generated %{NUMBER:generated_bytes} bytes in {NUMBER:secs} msecs (HTTP/1.0 %{NUMBER:response_code}) %{NUMBER:headers} headers in %{NUMBER:header_bytes} (1 switches on core 0) 

EDIT 2

sono finalmente in grado di rompere io stesso. Il filtro GROK per il registro di cui sopra sarà:

\[pid: %{NUMBER:pid}\|app: %{NUMBER:app}\|req: %{NUMBER:req_num1}/%{NUMBER:req_num2}\] %{IP:client_ip} \(\) \{%{NUMBER:vars} vars in %{NUMBER:bytes} bytes\} %{SYSLOG5424SD} %{WORD:method} /\?file_name\=%{NUMBER:file_name}\&start\=%{NUMBER:start}\&end\=%{NUMBER:end} \=\> generated %{NUMBER:generated_bytes} bytes in %{NUMBER:secs} msecs \(HTTP/1.0 %{NUMBER:response_code}\) %{NUMBER:headers} headers in %{NUMBER:header_bytes} 

Ma le mie domande rimangono ancora:

  1. c'è qualche difetto uwsgi accedere filtro grop ?? **

  2. I' ho applicato corrispondenze diverse per parametri di query diversi. C'è qualcosa nel grok che recupera da solo i diversi parametri di query ??

risposta

6

ho trovato la soluzione per l'estrazione dei parametri di query: -

Qui è la mia configurazione finale: -

Per la linea di registro

[pid: 7731|app: 0|req: 426435/426435] clientIP() {28 vars in 594 bytes} [Mon Mar 2 06:43:08 2015] GET /?file_name=wqvqwv&start=0&end=30&device_id=asdvqw&verif_id=qwevqwr&lang=English&country=in => generated 11018 bytes in 25 msecs (HTTP/1.0 200) 2 headers in 82 bytes (1 switches on core 0) 

la configurazione è

input { stdin { } } 

filter { 
    grok { 
    match => { "message" => "\[pid: %{NUMBER}\|app: %{NUMBER}\|req: %{NUMBER}/%{NUMBER}\] %{IP} \(\) \{%{NUMBER} vars in %{NUMBER} bytes\} %{SYSLOG5424SD:DATE} %{WORD} %{URIPATHPARAM} \=\> generated %{NUMBER} bytes in %{NUMBER} msecs \(HTTP/1.0 %{NUMBER}\) %{NUMBER} headers in %{NUMBER}" } 
    } 
    date { 
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] 
    } 
    kv { 
    field_split => "&? " 
    include_keys => [ "file_name", "device_id", "lang", "country"] 
    } 
} 


output { 
    stdout { codec => rubydebug } 
    elasticsearch { host => localhost } 
} 
3

Ho trovato che la tua soluzione non supporta HTTP/1.1. Ho risolto e anche aggiungere il nome delle variabili.Ref

Ecco la mia Grok config:

grok { 
    match => { "message" => "\[pid: %{NUMBER:pid}\|app: %{NUMBER:id}\|req: %{NUMBER:currentReq}/%{NUMBER:totalReq}\] %{IP:remoteAddr} \(%{WORD:remoteUser}?\) \{%{NUMBER:CGIVar} vars in %{NUMBER:CGISize} bytes\} %{SYSLOG5424SD:timestamp} %{WORD:method} %{URIPATHPARAM:uri} \=\> generated %{NUMBER:resSize} bytes in %{NUMBER:resTime} msecs \(HTTP/%{NUMBER:httpVer} %{NUMBER:status}\) %{NUMBER:headers} headers in %{NUMBER:headersSize} bytes %{GREEDYDATA:coreInfo}" } 
} 
date { 
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] 
}