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!

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