zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    .charAt()方法
    CustomerBiz方法运用
    面向对象_方法 判断
    方法
    查找无序数组索引
    面向对象_购票
    创建类 方法 构建类对象
    StringBuffer 方法
    docker创建redis mysql 等服务
    docker常用的命令
  • 原文地址:https://www.cnblogs.com/minseo/p/7067703.html
Copyright © 2011-2022 走看看