Splunk Search

How to use top in timechart

mprreddy51
Explorer

Hi All,

I have a requirement to use TOP 4 in the timechart command:

Below is my search:

index=_internal |timechart count by sourcetype limit=5 span=1d|addcoltotals

(7DAYS DATA)
I need the top 4 column values of (sourcetype) as shown in the screenshot like SPLUNKD,SPLUNK_UI_ACCESS,SPLUNK_WEB_ACCESS,SPLUNK_WEB_SERVICE only
alt text
Thanks
PR

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try like this

index=_internal | bucket span=1d _time | stats count by _time sourcetype | eventstats sum(count) as total by sourcetype | sort - total | streamstats current=f window=1 values(total) as prev | eval sno=case(isnull(prev),1,prev=total,0,1=1,1) | accum sno | where sno<5 | table _time sourcetype count | xyseries _time sourcetype count | addcoltotals

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try like this

index=_internal | bucket span=1d _time | stats count by _time sourcetype | eventstats sum(count) as total by sourcetype | sort - total | streamstats current=f window=1 values(total) as prev | eval sno=case(isnull(prev),1,prev=total,0,1=1,1) | accum sno | where sno<5 | table _time sourcetype count | xyseries _time sourcetype count | addcoltotals

mprreddy51
Explorer

Thanks Somesh

0 Karma

sundareshr
Legend

Couldn't the top 4 sourcetypes be different for each day?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...