Splunk Search

Top 10 Event Counts with date/time of last event

mmester
Explorer

Guys,

Im looking to figure out a way to determine when the last event happened in a top ten report. For example:

5/12/2013 12:00 500 apples
5/12/2015 13:00 225 Pears
Etc.

I currently have the query:

host="Clerk" sourcetype="fruitStand" | top 10 fruit

I use the table visualization.

Tags (4)
0 Karma
1 Solution

lguinn2
Legend

Try this instead:

host="Clerk" sourcetype="fruitStand" 
| stats count latest(_time) as latestTime by fruit
| sort -count
| fieldformat latestTime=strftime(latestTime,"%x %X")
| head 10

If you really need the percentage, add the following:

host="Clerk" sourcetype="fruitStand" 
| stats count latest(_time) as latestTime by fruit
| eventstats sum(count) as TotalCount
| eval percent=round(count*100/TotalCount)
| fields - TotalCount
| fieldformat latestTime=strftime(latestTime,"%x %X")
| sort -count
| head 10

View solution in original post

lguinn2
Legend

Try this instead:

host="Clerk" sourcetype="fruitStand" 
| stats count latest(_time) as latestTime by fruit
| sort -count
| fieldformat latestTime=strftime(latestTime,"%x %X")
| head 10

If you really need the percentage, add the following:

host="Clerk" sourcetype="fruitStand" 
| stats count latest(_time) as latestTime by fruit
| eventstats sum(count) as TotalCount
| eval percent=round(count*100/TotalCount)
| fields - TotalCount
| fieldformat latestTime=strftime(latestTime,"%x %X")
| sort -count
| head 10

mmester
Explorer

Thank you that worked perfectly

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...