Getting Data In

Average on time only, without considering date

andreafebbo
Communicator

I have this query:

 Base quey
| eval EndTime = if(Result="OK", _time, null)
| eval StartTime = if(LogType ="START", _time, null)
| stats Latest(StartTime) as StartTime Latest(EndTime) as EndTime by PackageName ExecutionInstanceGUID
| eval Duration = (EndTime-StartTime)
| where (Duration != "" OR Duration >= 0)
| stats avg(EndTime) as AVGEndTime avg(Duration) as AVGDuration avg(StartTime) as AVGStartTime by PackageName
| fieldformat AVGStartTime = strftime(AVGStartTime,"%H:%M:%S") 
| fieldformat AVGEndTime = strftime(AVGEndTime,"%H:%M:%S") 

My problems is that in calculating the average on AVGStartTime and AVGEndTime he considers the day also.
I'd like the average to be made just on the hour, minutes, seconds, not on the day.

Thanks.

0 Karma
1 Solution

somesoni2
Revered Legend

Try this

Base quey
 | eval EndTime = if(Result="OK", _time-relative_time(_time,"@d"), null)
 | eval StartTime = if(LogType ="START", _time-relative_time(_time,"@d"), null)
 | stats Latest(StartTime) as StartTime Latest(EndTime) as EndTime by PackageName ExecutionInstanceGUID
 | eval Duration = (EndTime-StartTime)
 | where (Duration != "" OR Duration >= 0)
 | stats avg(EndTime) as AVGEndTime avg(Duration) as AVGDuration avg(StartTime) as AVGStartTime by PackageName
 | fieldformat AVGStartTime = strftime(AVGStartTime,"%H:%M:%S") 
 | fieldformat AVGEndTime = strftime(AVGEndTime,"%H:%M:%S") 

View solution in original post

somesoni2
Revered Legend

Try this

Base quey
 | eval EndTime = if(Result="OK", _time-relative_time(_time,"@d"), null)
 | eval StartTime = if(LogType ="START", _time-relative_time(_time,"@d"), null)
 | stats Latest(StartTime) as StartTime Latest(EndTime) as EndTime by PackageName ExecutionInstanceGUID
 | eval Duration = (EndTime-StartTime)
 | where (Duration != "" OR Duration >= 0)
 | stats avg(EndTime) as AVGEndTime avg(Duration) as AVGDuration avg(StartTime) as AVGStartTime by PackageName
 | fieldformat AVGStartTime = strftime(AVGStartTime,"%H:%M:%S") 
 | fieldformat AVGEndTime = strftime(AVGEndTime,"%H:%M:%S") 

woodcock
Esteemed Legend

Show the output as it is now and then show the desired output. I do not understand "the problem" and how "he considers the day" because that part is not in the search. Show us the entire search.

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!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...