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!

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...