Splunk Search

Average Timespan

RagtimeWilly
Explorer

I have a large amount of logs in the following format:

2014-07-30 14:23:51,802 - MyApp - 6 - INFO - Performance - process=Update, timeElapsed=00:00:00.0940611

I have a filter which displays only these entries:

Service=MyApp source="C:\Logs\MyApp-Performance.log" process=Update

Would someone be able to explain how I can update this go that it give me the average timeElapsed across all entries for the selected period?

Apologies, I'm new to this and have tried a few different things but can't seem to figure it out.

Thanks in advance,

Tags (2)
1 Solution

somesoni2
Revered Legend

Give this a try

Service=MyApp source="C:\Logs\MyApp-Performance.log" process=Update| eval duration=strptime(timeElapsed,"%H:%M:%S.%6Q")-relative_time(now(),"@d") | stats avg(duration) as avgTimeElapsed 

The field timeElapsed is string to need to convert it to seconds before calculating avg.

View solution in original post

somesoni2
Revered Legend

Give this a try

Service=MyApp source="C:\Logs\MyApp-Performance.log" process=Update| eval duration=strptime(timeElapsed,"%H:%M:%S.%6Q")-relative_time(now(),"@d") | stats avg(duration) as avgTimeElapsed 

The field timeElapsed is string to need to convert it to seconds before calculating avg.

RagtimeWilly
Explorer

This worked a charm!

Thank you!

0 Karma

tom_frotscher
Builder

Hi,

you can append an | stats avg(timeElapsed) to your search query.

tom_frotscher
Builder

Yeah, sorry! Did't saw that the field is not properly converted for use with stats. But @somesoni2 got it!

0 Karma

RagtimeWilly
Explorer

Thanks for the response.

This is one of the things I tried but I just get a message saying "No results found"

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

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 ...