Splunk Search

How to find events where the event time duration is greater than the overall dynamic average time?

wandi
Explorer

I have a field named "time" where I have the time that an event took and a field named "tag" with the name of the event. I want to search all the tags that time are greater than overall time average. Something like:


source=avpiv2 | where time > [search source=apiv2 | stats avg(time) as averageTime | return averageTime]

but I'm receiving the error:
Error in 'where' command: The operator at '="20.436350"' is invalid.
(note that 20.43... is the dynamic number that I want to use in the comparison)

Tags (3)
0 Karma
1 Solution

gauldridge
Path Finder

Try this:

source=avpiv2 | where time > [search source=apiv2 | stats avg(time) as averageTime | fields averageTime | rename averageTime AS search]

When you rename a field to search in a subsearch, you get just the value of the field returned to your main search pipeline vice returning a field/value pair. So, your search is returning averageTime=20.436350 instead of just 20.436350 like you expect.

View solution in original post

gauldridge
Path Finder

Try this:

source=avpiv2 | where time > [search source=apiv2 | stats avg(time) as averageTime | fields averageTime | rename averageTime AS search]

When you rename a field to search in a subsearch, you get just the value of the field returned to your main search pipeline vice returning a field/value pair. So, your search is returning averageTime=20.436350 instead of just 20.436350 like you expect.

unnigec
Engager

since we are pulling out only averageTime here ...|fields averageTime does not do any extra job I suppose.

0 Karma

somesoni2
Revered Legend

Alternatively, your can use "| return $averageTime", if just running a search on Search App [ user "|return $$averageTime" in case of dashboards searches] instead of just " |return averageTime" in the subsearch.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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