Splunk Search

How to parse a time duration of the format "4s", "9.1ms", etc.

dankinder
New Member

The default duration output from go (golang) is to use a single float with one or two characters identifying the unit, ex:

56.920404ms
4.61µs
45.1s
etc.

I can't seem to find a built-in way to convert these. How can it be done?

0 Karma

lguinn2
Legend

Try this, assuming that your duration output is in a field called duration

yoursearchhere
| convert rmunit(duration) as num_duration
| rex field=duration "\d*\s*(?<units>\w+)$"
| eval secs=num_duration * case(units=="s",1,  units="ms",.001, units="µs",.000001,units=="m",60,1==1,0)

The result is a field called secs that contains the duration converted to seconds.
Clearly, I did not do all possible units, but you get the point.
AFAIK, there is no single command or function that will do what you want. You could turn this into a macro though

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...