Splunk Search

How to get top values

xvxt006
Contributor

Hi, i have a report where i show top 50 404s by uri as shown below. Now i want to get the top referer for each URI in the same report. is it possible?

URI COUNT %

XXX 50 50%
YYY 25 25%
ZZZ 25 25%

output should have
URI COUNT % Referer Referercount REferer%
XXX 50 50%
YYY 25 25%
ZZZ 25 25%

Tags (1)
0 Karma
1 Solution

thslopes
Explorer
yoursearch | top uri | join uri [search yoursearch | top uri referrer | eval referer_count=count | eval referer_percent=percent] | table uri count percent referrer referer_count referer_percent

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Here's an approach to keep things within one search:

your search yielding 404 events | stats c by uri referer | eventstats max(c) as max sum(c) as count by uri | where max==c | fields - max c

You may want to sort, calculate percentages, and cut after the first n results afterwards to look similar to top.
Note: This does not handle cases where the top referers for one uri have equal counts. If that's important for you you can insert a ... | streamstats count as number by uri referer | where number==1 | fields - number at the end.

0 Karma

thslopes
Explorer
yoursearch | top uri | join uri [search yoursearch | top uri referrer | eval referer_count=count | eval referer_percent=percent] | table uri count percent referrer referer_count referer_percent

xvxt006
Contributor

Thank you all for your inputs

0 Karma

lukejadamec
Super Champion

You can try:

|top limit=50 uri |append [yoursearch |top top limit=50 referer by uri]

I've not tried this, but in theory it should work.

lukejadamec
Super Champion

Right, you want to maintain the numbers for both. I updated the answer.

0 Karma

xvxt006
Contributor

that will give me top referers but i want to get top uris for 404s and then for those uris i need top referers

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