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
Revered Legend

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!

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