Splunk Search

How to convert seconds to milliseconds by stripping out seconds and then add it to milliseconds?

raghul725
Explorer

Hello,

I am performing the following search to extract the time taken to upload

 

index=* my_search |rex "\[upload\] executed in (?<ut>\d+\w+)"

the above extracts values like 343ms, 8s30ms, 11s404ms

How would I extract the seconds portion, convert it into ms and add it to ms so that I can get the upload time always in ms please?

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

As with many things Splunk, there's probably more than one way to do that.  I like rex for it.  Use a regular expression to extract the s and ms values then use eval for the math.

index=* my_search
| rex "\[upload\] executed in (?<ut>\d+\w+)"
| rex field=ut "(?:(?<sec>\d+)s)?(?<ms>\d+)ms"
``` Convert null to zero ```
| eval sec = if(isnull(sec), 0, sec)
| eval ms = (sec*1000) + ms
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

As with many things Splunk, there's probably more than one way to do that.  I like rex for it.  Use a regular expression to extract the s and ms values then use eval for the math.

index=* my_search
| rex "\[upload\] executed in (?<ut>\d+\w+)"
| rex field=ut "(?:(?<sec>\d+)s)?(?<ms>\d+)ms"
``` Convert null to zero ```
| eval sec = if(isnull(sec), 0, sec)
| eval ms = (sec*1000) + ms
---
If this reply helps you, Karma would be appreciated.
0 Karma

raghul725
Explorer

Brilliant thank you very much

Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...