• logstash 根据type 判断输出


    # 更多ELK资料请访问 http://devops.taobao.com
    
    一、配置前需要注意:
    
    1.Use chmod to modify nginx log file privilege. E.g. chmod 664 access.log
    2.Modify /etc/default/logstash => LS_USER field to change logstash user, e.g. root
    
    
    --------------------------------------------------------------------------
    
    
    二、logstash配置文件:
    
    input {
        file {
            type => "nginx-access"
            path => "/var/nginx/access.log" # MODIFY REQUIRED! point to nginx access.log file
            start_position => beginning  # read file from beginning, instead of from end as default
            ignore_older => 0            # do not ignore old file
        }
        file {
            type => "nginx-error"
            path => "/var/nginx/error.log" # MODIFY REQUIRED! point to nginx error.log file
            start_position => beginning
            ignore_older => 0
        }
    }
    
    filter {
        # separate parsing for nginx access and error log
        if [type] == "nginx-access" {
            # default nginx access log pattern (nginx 1.4.6). You may change it if it doesn't fit
            grok {
                match => { "message" => "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}" }
            }
        } else if [type] == "nginx-error" {
            # default nginx error log pattern (nginx 1.4.6). You may change it if it doesn't fit (but ensure "clientip" field)
            grok {
                match => [ "message" , "(?<timestamp>%{YEAR}[./-]%{MONTHNUM}[./-]%{MONTHDAY}[- ]%{TIME}) [%{LOGLEVEL:severity}] %{POSINT:pid}#%{NUMBER}: %{GREEDYDATA:errormessage}(?:, client: (?<clientip>%{IP}|%{HOSTNAME}))(?:, server: %{IPORHOST:server}?)(?:, request: %{QS:request})?(?:, upstream: (?<upstream>"%{URI}"|%{QS}))?(?:, host: %{QS:request_host})?(?:, referrer: "%{URI:referrer}")?"]
            }
        }
    
        # add geo-location info
        geoip {
            source => "clientip"
        }
    }
    
    output {
        # output to local Elasticsearch server as index, separated by log type and date
        elasticsearch {
            hosts => ["127.0.0.1"]
            index => "%{type}-%{+YYYY.MM.dd}"
        }
    }
    
    
    
    --------------------------------------------------------------------------
    
    github地址:https://github.com/adventure-yunfei/ELK-for-nginx-log
    
    
    
    
    

  • 相关阅读:
    golang 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
    BITOP operation destkey key [key ...]
    Viscosity for Mac使用创建您的第一个连接的方法
    ubuntu18没有网络连接Network
    go1.14下Go mod使用实践
    Unity 光照系统
    Unity 单例模式
    Unity 回调函数(Callback)
    Unity 基于OnGUI显示实时FPS
    Unity OnGUI 的可视化编辑
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199337.html
Copyright © 2020-2023  润新知