Splunk Search

How to do this search?

hjwang
Contributor

Hi~there,

The first search is quite simple, just extract top 10 stats count by src, so i use

my search | stats count by src | sort - count | head 10

but now i wanna use this top 10 src to separately list its top 50 events, how can I do this? Thanks in advance.

just like follows:

src,     count,   event
---      -----    -----
x.x.x.1   500     1.the first   raw event
                  2.the second  raw event
                  3.the third   raw event
                  .
                  .
                  50.the 50th   raw event
x.x.x.2   200     1.the first   raw event
                  2.the second  raw event
                  3.the third   raw event
                  .
                  .
                  50.the 50th   raw event
.
.
.
x.x.x.10  300     1.the first   raw event
                  2.the second  raw event
                  3.the third   raw event
                  .
                  .
                  50.the 50th   raw event
Tags (2)
0 Karma

gkanapathy
Splunk Employee
Splunk Employee
... | eventstats count by src | dedup 50 src sortby count,src | streamstats global=t current=t dc(src) as rank | where rank <= 10

Then, if you want to to display with nulls in your data, you can add:

... | dedup keepevents=t src,count

But that is purely for display purposes as it founds up your data. This will be rather more efficient than using a subsearch in your case, as it uses a single pass over the data rather than two passes.

0 Karma

hjwang
Contributor

streamstats means "Adds summary statistics to all search results in a streaming manner". but i don't really understand about streaming manner and its difference with eventstats.

0 Karma

Ayn
Legend

This is a very good example of a situation where a subsearch can be used. Use your first search to single out the hosts with the most events, then feed those hosts into your outer search and generate the statistics:

* [my search | stats count by src | sort - count | head 10] | stats count,values(_raw) by src

More information on subsearches can be found in the docs:

http://www.splunk.com/base/Documentation/4.2.2/User/Subsearchtutorial

http://www.splunk.com/base/Documentation/latest/User/HowSubsearchesWork

0 Karma

hjwang
Contributor

here, i have doubt that if using values(_raw) how can i extract only head 50 raw event ? thanks

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...