【问题标题】:elasticsearch-logstash time difference calculation (ELK 5.3)elasticsearch-logstash 时差计算(ELK 5.3)
【发布时间】:2017-04-10 00:44:35
【问题描述】:

我需要在没有经过插件的情况下手动计算时差,因为我的结束时间会发生变化,并且可能需要 24 小时的大量日志。 我设法通过以下方式从旧日志中获取开始时间:

elasticsearch {
                query => "Event:'Sent' AND ID:%{[ID]}"
                index => "mylog*"
                result_size => "1"
                enable_sort => "false"
                fields => { "@timestamp" => "SentTime" }
        }

它实际上工作正常并以“2017-03-29T22:00:03.000Z”格式返回正确的日期

但它会变坏: 以这种格式返回值“1970 年 1 月 18 日,08:07:09.056”

 ruby {
          code => "event.set('[SecondsToDeliver]', event.get('@timestamp').to_f - event.get('SentTime').to_f)"
          add_tag => [ "rubyfilter" ]
         }

我确定这是一个微不足道的语法错误,但我无法捕捉到它。

【问题讨论】:

    标签: ruby elasticsearch logstash elasticsearch-5


    【解决方案1】:

    通过这个数学解决:

    elasticsearch {
                            hosts => ["Your elastic host"]
                            query => 'Event:"Sent" AND ID:"%{ID}"'
                            fields => { "@timestamp" => "SentTime" }
                            tag_on_failure => [ "NoSent_ID" ]
                    }
    
                 date {
                    match => ["[SentTime]", "ISO8601"]
                    target => "[SentTime]"
                 }
            ruby {
                        init => "require 'time'"
                        code => "duration = (event.get('@timestamp') - event.get('SentTime')) rescue nil; event.set('Log_duration', duration); "
                     }
    

    【讨论】:

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