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!

What the End of Support for Splunk Add-on Builder Means for You

Hello Splunk Community! We want to share an important update regarding the future of the Splunk Add-on Builder ...

Solve, Learn, Repeat: New Puzzle Channel Now Live

Welcome to the Splunk Puzzle PlaygroundIf you are anything like me, you love to solve problems, and what ...

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...