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!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...