Splunk Search

How to search top 5 IPs with highest distinct count emails per day?

niboucher
Explorer

Hello,

In each line of the logs ,there is an email, an IP address and a timestamp.

I'd like to calculate for each day the top 1 (or top 5 or top 10) IPs which have the biggest number of distinct emails.

I'm using this

| bin span=1d _time
| stats dc(email) by ip,_time

but this doesn't do the trick since it prints a line for each IP and each day and I don't know to get only the top 5 dc(email) per IP

I'd like the result to look like this

_time        dc(email)    ip

2014-07-28   50           10.1.1.1
             30           1.1.1.2
             20           1.1.1.3
             10           1.1.1.4
             10           1.1.1.4
2014-07-29   120          10.9.1.1
             85           25.1.1.2
             45           34.1.1.3
             35           26.1.1.4
             15           42.1.1.4

Do you guys know how to do this?

Tags (4)

somesoni2
Revered Legend

Another way of achieving the same

your base search | bin span=1d _time | stats dc(email) as dc by ip,_time | sort _time,dc | streamstats count by _time | where count < 6
0 Karma

somesoni2
Revered Legend

It indeed should be <6. Thanks for pointing it out. I guess I'm in mood for early Friday..

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Wouldn't that be where count < 6?

0 Karma

aelliott
Motivator

Try something like this:

|bucket _time span=1d | eventstats dc(email) by ip | top limit=5 dc(email),ip by _time |sort -_time, -dc(email)

aelliott
Motivator

Updated the answer, should be good now.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...