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

2019-07-03 23:10发布

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?

2条回答
再贱就再见
2楼-- · 2019-07-03 23:19

This is what ended up working.

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

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

```

查看更多
在下西门庆
3楼-- · 2019-07-03 23:31

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"
  }
}
查看更多
登录 后发表回答