Logstash filter to convert “$epoch.$microsec” to “$epoch_millis”

我的未来我决定 提交于 2019-12-10 21:48:00

问题


I am trying to convert a timestamp field that is in the form $epoch.$microsec to $epoch_millis.

Example:

1415311569.541062  -->  1415311569541

Logstash doesn't appear to have any means of multiplying numbers so ts * 1000 and casting to a long is out.

Any ideas?


回答1:


In your particular case you can indeed get away with turning the problem into a string manipulation problem, but you can also use the ruby filter:

filter {
  ruby {
    # do some calculation
    code => "event['ts'] = (1000 * event['ts'].to_f).round"
  }
}



回答2:


This is what ended up working.

mutate {
        convert => { 
            "ts" => "string"
        }

        gsub => [
            "ts", "\.", "",
            "ts", "\d{3}$", ""
        ]
}

```



来源:https://stackoverflow.com/questions/26790543/logstash-filter-to-convert-epoch-microsec-to-epoch-millis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!