logstash實戰filter插件之grok(收集apache日志)


有些日志(比如apache)不像nginx那樣支持json可以使用grok插件

grok利用正則表達式就行匹配拆分

預定義的位置在

/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-2.0.5/patterns

apache的在文件grok-patterns 

查看官方文檔

https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html

 

vim /etc/logstash/conf.d/grok.conf

input{
    stdin{}
}

filter {
  grok {
    match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" }
  }
}


output{
   stdout{
        codec => rubydebug
   }
}

  啟動

/opt/logstash/bin/logstash -f grok.conf

標准輸入文本 55.3.244.1 GET /index.html 15824 0.043

輸出

 

PS:grok非常影響性能,不靈活,可以使用logstash - redis - python -es

 

vim apache_grok.conf

input{
    stdin{}
}


filter{
    grok{
     match => { "message" => "%{HTTPD_COMBINEDLOG}" }
   }
}

output{
    stdout{
        codec => rubydebug
    }
}

  

運行輸出

/opt/logstash/bin/logstash -f apache_grok.conf

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM