【问题标题】:ELK - Time difference calculation on LogstashELK - Logstash 上的时差计算
【发布时间】:2019-12-20 14:08:45
【问题描述】:

我需要从下面提到的日志中计算两个事件之间的时间差并在 Kibana 上显示相同,我有一个唯一的标识符和消息来识别。

2019-12-20 13:00:22.493 [http-nio-8080-exec-2933] INFO  c.g.i.g.m.c.GRInternalController.getGRForPO(68) - Request Started
2019-12-20 13:00:30.882 [http-nio-8080-exec-2933] INFO  c.g.i.g.m.s.i.GoodsReceiptServiceImpl.getGRForPO(1647) - Request Completed

2019-12-20 13:01:02.570 [http-nio-8080-exec-2940] INFO  c.g.i.g.m.c.GRInternalController.getGRForPO(68) - Request Started
2019-12-20 13:01:09.930 [http-nio-8080-exec-2940] INFO  c.g.i.g.m.s.i.GoodsReceiptServiceImpl.getGRForPO(1647) - Request Completed

事件的唯一标识符:[http-nio-8080-exec-2933][http-nio-8080-exec-2940]

[http-nio-8080-exec-2933] 的时间差异:8.389

[http-nio-8080-exec-2940] 的时间差异:7.36

有人可以提出解决方案吗?提前致谢。

【问题讨论】:

    标签: logstash elastic-stack elk elapsedtime


    【解决方案1】:

    我们可以在 logstash 上使用 ruby​​ 过滤器来实现:

    ruby {
    
           code => "duration = 
                    (DateTime.parse(event.get('time1')).to_time.to_f*1000-DateTime.parse(event.get('time2')).to_time.to_f*1000) rescue nil; 
                    event.set('timedifference', duration); "
                }
    

    时间差将以毫秒为单位。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 2013-09-05
      相关资源
      最近更新 更多