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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...