Splunk Search

How to "stats avg(field1) by field2" and display that average in a top limit=20 field2 stats page

shantu
Explorer

I'm working with Alert logs, which spit out log events only if certain SQL queries take longer than a threshold time. Each log event has two values of interest - QueryTime and SQLQuery. I'm extracting these fields.

I'd like to run a "top limit=50 SQLQuery showperc=f" and I'd like to add a column to show "avg(QueryTime) by SQLQuery". Can't figure out a way to do both in the same search. The end result should have the following headers:

SQLQuery avg(QueryTime) Count

Tags (3)
0 Karma
1 Solution

acharlieh
Influencer

You want the average times of the 50 most common sql queries? what if instead of top we make use of sort to sort by the count, and then limit our result set, keeping the average query times in tact like so:

... | stats count avg(QueryTime) by SQLQuery | sort 50 - count

View solution in original post

acharlieh
Influencer

You want the average times of the 50 most common sql queries? what if instead of top we make use of sort to sort by the count, and then limit our result set, keeping the average query times in tact like so:

... | stats count avg(QueryTime) by SQLQuery | sort 50 - count

shantu
Explorer

That worked as required. Thanks!

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...