Splunk Search

Need to use top-like useother functionality with chart command.

lyndac
Contributor

I have some json data that was indexed with sourcetype=_json. There is one field in the json that is an array. I need to show a chart of the counts by the values in the array. The wrinkle is that one of the values in the array is special. It should ONLY be counted if it is the ONLY value of the array. For example, if the array looks like:

procs{} = A, B, special
procs{} = B, special
procs{} = special
procs{} = C,B

The counts should be: A: 1, B:3, C:1, special:1

index=foo | rename procs{} as procs | eval numprocs=mvcount(procs) | mvexpand(procs) | stats count(eval((procs="special" AND numprocs=1) OR (procs != "special"))) as count by procs | sort -count | head 10

This search works great. However, I need to only show the top 10 procs and have an "other" column similar to how top works. How would I do that?

Tags (3)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Try something like this:

... | sort -count | eventstats sum(count) as total | streamstats count as number | head 11 | eventstats sum(count) as total2 | eval count = if(number==11, total2 - total, count) | eval procs = if(number=11, "OTHER", procs) | fields - total total2 number

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try something like this

index=foo | rename procs{} as procs | eval procs=mvcount(procs) | mvexpand(procs) | stats count(eval((procs="special" AND numprocs=1) OR (procs != "special"))) as count by procs | sort -count | eval sno=1 | accum sno | eval procs=if(sno>10,"OTHER",procs) | stats sum(count) as count by procs
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Try something like this:

... | sort -count | eventstats sum(count) as total | streamstats count as number | head 11 | eventstats sum(count) as total2 | eval count = if(number==11, total2 - total, count) | eval procs = if(number=11, "OTHER", procs) | fields - total total2 number
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...