Splunk Search

How to evaluate if a value is in Seconds and only then convert to Miliseconds

TotallyJuvenile
Loves-to-Learn

I am trying to parse some data for API latency. I have a value for "elapsedTime" which spits that out. However if a request takes longer than 999ms, then it changes to reporting in seconds. So... the query below could return 999ms or 1.001s. What eval statement do I need here to parse the value of elapsedTime and if it contains "s" and not "ms",  then * 1000 to get a value in ms...

| NEED SOME EVAL HERE I GUESS | stats min(elapsedTime) as Fastest max(elapsedTime) as Slowest avg(elapsedTime) as "Average"

Labels (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Simple way is to first extract the numeric value and the time specifier, then use eval to do the test/calc

| rex field=elapsedTime "(?<timeValue>[\d\.]*)(?<timeSpecifier>(ms|s))"
| eval elapsedTime=if(timeSpecifier="ms", timeValue, timeValue*1000)

 

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...