Splunk Search

Stats Distinct Count (X) + X[Values]

JRamirezEnosys
Explorer

Hi Splunkers,

I have a query that gives me the following fields I want to work with.

username
Country (after using iplocation on src_ip)

Some usernames have login from more than 2 countries.

I want to see it on a chart that shows me the top 5 usernames based on how many countries they have log in and which countries are those.

I believe I need to use dc(Country) at some point

This is my search string

index=main event=sso status=success ip!=10.0.0.0/8  | regex subject=^\D\d+$ | iplocation ip | stats dc(Country) by subject
Tags (1)
0 Karma

DalJeanis
SplunkTrust
SplunkTrust

Based on your description and code, I have to assume that the field "subject" is holding the username...

0 Karma

andrey2007
Contributor

Try this

index=main event=sso status=success ip!=10.0.0.0/8  | regex subject=^\D\d+$ | iplocation ip | stats dc(Country)  as Country_count values(Country) as Countries by subject | sort 5 - Country_count

somesoni2
SplunkTrust
SplunkTrust

If your end goal is to see the chart, try this version and select a stacked column/bar chart.

index=main event=sso status=success ip!=10.0.0.0/8  | regex subject=^\D\d+$ | iplocation ip | stats dc(Country)  as Country_count values(Country) as Countries by subject | sort 5 - Country_count
| mvexpand Countries | chart count over subject by Countries
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 ...