Logstash convert String into milliseconds


I am using logstash to convert below two strings into integer and then converting integer to milliseconds.

i have nginx logs with below values


first i am converting them into float

  mutate {
    convert => ["request_time", "float"]
    convert => ["response_time", "float"]

and them am trying to convert them into milliseconds with below method, but am getting zero printing in the kibana

ruby {
  code => "event.set('request_time', event.get('request_time').to_i * 1000)"

Screen Shot 2019-12-30 at 4.27.39 PM

The .to_i will round them down to zero, I think. Does it work if you use this?

(event.get('request_time') * 1000.0).to_i

Thats works, thanks for suggestion.

i have different issue while adding 2 strings into condition like below.

ruby {
code => "event.set('request_time', event.get('request_time') * 1000.0).to_i"
code => "event.set('response_time', event.get('response_time') * 1000.0).to_i"

is this correct format ?

Not sure if that works or if one code option overwrites the other. I would use

ruby {
    code => "
        event.set('request_time', event.get('request_time') * 1000.0).to_i
        event.set('response_time', event.get('response_time') * 1000.0).to_i

That works, thanks!!!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.