ELK测试 logstash 配置,包含解析时间字段

input {   #使用beats 收集 日志
    beats {
        port => "5044"
    }
}

filter {
if [fields][logtype] ==  "access" {
    grok {
        match => {
          "message" => '%{HTTPDATE:logdate}'   #得到时间格式 15/May/2019:19:45:31 +0800,时间格式由日志中格式决定
          "message" => '%{IP:clientip}'
        }
    }

 #HTTPDATE, IP 规则在https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/grok-patterns , 可以自定义

    date {
        match => ["logdate", "dd/MMM/yyyy:HH:mm:ss Z"]  #匹配日志中的时间 到logdate
    }
    geoip {
    source => "clientip"
    target => "geoip"
    }
}
  if [fields][logtype] ==  "catalina" {
   grok {
    match => {
      "message" => '%{TIMESTAMP_ISO8601:logdate}'  #匹配日志中的时间 到logdate, 得到时间格式 2019-5-16 03:12:40时间格式由日志中格式决定
    }
 
        pattern_definitions => {
            "MESSAGE" => "[\s\S]*"
        }
    }
    date {  #使用logdate到@timestamp  l
        match => ["logdate", "yyyy-MM-dd HH:mm:ss","dd/MM/yyyy:HH:mm:ss Z"]  
            locale => en
            timezone => "+0800"  #由于logdate 没带时区,应用到@timestamp 中会有时区转换, 不加会导致时间戳会+8 小时
    }

  }
}

output {
  if [fields][logtype] ==  "catalina" {
    elasticsearch {
      hosts => ["host_IP:9200"]
      index => "%{[fields][env]}-catalina-%{+YYYY-MM}" #按月划分index 
    }
  }
  if [fields][logtype] ==  "access" {
    elasticsearch {
      hosts => ["host_IP:9200"]
      index => "%{[fields][env]}-access-%{+YYYY-MM}"
    }
  }
}

目前使用版本ELKB7.0 详细看官网https://www.elastic.co/guide/en/logstash/current/index.html  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值