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!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...