Splunk Search

Average duration

DTERM
Contributor

What is the syntax to obtain the average duration for each severity type in a query? A field exists called app_duration=0d 0h 40m 3s. I need the average for each severity type.

Thanks.

Tags (1)
1 Solution

bwooden
Splunk Employee
Splunk Employee

First convert the app_duration to a format convert can use. Then, use convert to store app_duration in seconds. Next, average all seconds by severity_type. Finally, re-format avg_app_duration for each severity_type in the human readable format of HH:MM:SS.

eval app_duration=replace(replace(replace(app_duration,"d\s","+"),"h|m|s",""),"\s",":") 
| convert dur2sec(app_duration) 
| stats avg(app_duration) as avg_app_duration by severity_type 
| eval avg_app_duration=tostring(round(avg_app_duration,0),"duration")

View solution in original post

bwooden
Splunk Employee
Splunk Employee

First convert the app_duration to a format convert can use. Then, use convert to store app_duration in seconds. Next, average all seconds by severity_type. Finally, re-format avg_app_duration for each severity_type in the human readable format of HH:MM:SS.

eval app_duration=replace(replace(replace(app_duration,"d\s","+"),"h|m|s",""),"\s",":") 
| convert dur2sec(app_duration) 
| stats avg(app_duration) as avg_app_duration by severity_type 
| eval avg_app_duration=tostring(round(avg_app_duration,0),"duration")
Get Updates on the Splunk Community!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...