logstash导入日志到elasticsearch时提取日志时间不支持2位数字年简写

logstash导入日志到elasticsearch时提取日志时间作为@timestamp属性。

filter{
	grok{
	  match => {"message" => "(?<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})\s*%{LOGLEVEL:loglevel}\s*%{GREEDYDATA:msg}"}
	} ### 通过grok匹配内容并将
	date{
	  match => ["datetime","yyyy-MM-dd HH:mm:ss"]
	  target => "@timestamp"
	} ### 处理时间
}

日志信息格式:

2022-04-08 04:20:53 INFO  [http-nio-8804-exec-6]>>>>>>>>>>sessionIde958c7b8-281e-48a9-9b65-294c50fd47cc - c.f.w.c.i.c.i.AuthChannelImpl[notAuth]

日志解析输出结果:

{
      "loglevel" => "INFO",
           "msg" => "[http-nio-8804-exec-6]>>>>>>>>>>sessionIde958c7b8-281e-48a9-9b65-294c50fd47cc - c.f.w.c.i.c.i.AuthChannelImpl[notAuth]\r",
          "type" => "type1",
      "datetime" => "2022-04-08 04:20:53",
      "@version" => "1",
          "host" => "DESKTOP-O93E7VQ",
    "@timestamp" => 2022-04-07T20:20:53.000Z,
          "path" => "e:/logstash-test/log-info.log",
       "message" => "2022-04-08 04:20:53 INFO  [http-nio-8804-exec-6]>>>>>>>>>>sessionIde958c7b8-281e-48a9-9b65-294c50fd47cc - c.f.w.c.i.c.i.AuthChannelImpl[notAuth]\r"
}

可见,上述的日志格式和提取配置是正确的。

开始的时候的配置如下(年采用两位数字简写方式):

filter{
	grok{
	  match => {"message" => "(?<datetime>\d{2}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})\s*%{LOGLEVEL:loglevel}\s*%{GREEDYDATA:msg}"}
	} ### 通过grok匹配内容并将
	date{
	  match => ["datetime","yy-MM-dd HH:mm:ss"]
	  target => "@timestamp"
	} ### 处理时间
}

日志格式:

22-04-08 04:20:53 INFO  [http-nio-8804-exec-6]>>>>>>>>>>sessionIde958c7b8-281e-48a9-9b65-294c50fd47cc - c.f.w.c.i.c.i.AuthChannelImpl[notAuth]

该配置方式和日志,不能将日志中的日期时间替换为日志的日期时间,所以日志的日期时间时导入时系统的日期时间。

也就是说,提取日志中的日期时间,作为导入es的日志时间时,不支持年的2位数字简写方式。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值