Splunk Search

Finding the AVG for requests over 3 seconds

joe06031990
Communicator

Hi,

 

I am trying to get the AVG response time for calls over 3 seconds and have the bellow:

 

index=test sourcetype="test"
| bin span=1d _time
| table response_time
| eventstats count as Event
| eval ResponseTime=response_time/1000
| eval isOver3s=if(ResponseTime>3,1,0)
| stats values(Event) as "Event",avg(ResponseTime) as "Average Response" ,sum(isOver3s) as "isOver3s" max(ResponseTime) as "Max Response Time" avg(eval(ResponseTime>=3)) as avgisOver3s
| eval Percentage=round((isOver3s/Event)*100,2)
| table Event "Average Response" isOver3s Percentage ,"Max Response Time", avgisOver3s

 

However the AVG response for the over 3 seconds is less than the normal AVG which is incorrect.

Any help would be greatly Appreciated.

 

Thanks,

 

Joe  

Labels (5)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

You're overcomplicating things 🙂

Firstly - why the bin and table?

Secondly - it should be enough to "scale" the response_time down (you can do this before or after statsing) and then stats. That's it.

There's one trick about the eval though. It seems that eval produces an actual numerical result which is fine with count but seems to break some more fancy stats functions (like avg) so effectively you're doing an avg of 1 (because that's what it gets cast to). You got 1 as the result of your avg, right? So in order to get any reasonable value you have to do some neat replacement.

index=test sourcetype="test"
| eval RT=response_time/1000
| stats count AS "Number of Events"
avg(RT) as "Average Response Time"
count(eval(RT>3)) AS "Number of long responses"
max(RT) AS "Maximum response time"
avg(eval(if(RT>3,RT,null()))) AS "Average long response"

And so on.

View solution in original post

0 Karma

PickleRick
SplunkTrust
SplunkTrust

You're overcomplicating things 🙂

Firstly - why the bin and table?

Secondly - it should be enough to "scale" the response_time down (you can do this before or after statsing) and then stats. That's it.

There's one trick about the eval though. It seems that eval produces an actual numerical result which is fine with count but seems to break some more fancy stats functions (like avg) so effectively you're doing an avg of 1 (because that's what it gets cast to). You got 1 as the result of your avg, right? So in order to get any reasonable value you have to do some neat replacement.

index=test sourcetype="test"
| eval RT=response_time/1000
| stats count AS "Number of Events"
avg(RT) as "Average Response Time"
count(eval(RT>3)) AS "Number of long responses"
max(RT) AS "Maximum response time"
avg(eval(if(RT>3,RT,null()))) AS "Average long response"

And so on.

0 Karma

joe06031990
Communicator

Thanks for your help.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...