Splunk Search

How to count the unique values of an extracted field by month?

di2esysadmin
Path Finder

We're trying to understand what our growth rate is in Nexus usage. I've been asked to find the unique number of users that log in month over month for the last year or so.

The following search correctly counts the number of unique usernames over the timespan of the search.

index=main host=nexs*prod* "Searching for user" source="/data/sonatype-work/nexus/logs/nexus.log*" source!="/data/sonatype-work/nexus/logs/nexus.log*.tmp" | stats dc(username)

But I've been unsuccessful in getting the results for number of unique usernames for Jan, Feb, Mar, etc. I've tried all kinds of combinations. Can someone help?

THANKS!

0 Karma

woodcock
Esteemed Legend

Like this:

index=main host=nexs*prod* "Searching for user" source="/data/sonatype-work/nexus/logs/nexus.log*" source!="/data/sonatype-work/nexus/logs/nexus.log*.tmp" | eval date_month=strftime(_time, "%b") | chart dc(clerkID) BY host date_month
0 Karma

woodcock
Esteemed Legend

Did this work for you?

0 Karma

di2esysadmin
Path Finder

Sorry. I didn't try every suggestion. I will though. 🙂

0 Karma

woodcock
Esteemed Legend

Once you do, pick the best one and click Answer to close the question.

0 Karma

renjith_nair
Legend

Does this help you?

index=main host=nexs*prod* "Searching for user" source="/data/sonatype-work/nexus/logs/nexus.log*" source!="/data/sonatype-work/nexus/logs/nexus.log*.tmp" |timechart span=1mon values(username)

If the result is the expected one, then you can adjust the search to show Month name and also mvexpand to expand the list

    index=main host=nexs*prod* "Searching for user" source="/data/sonatype-work/nexus/logs/nexus.log*" source!="/data/sonatype-work/nexus/logs/nexus.log*.tmp" |timechart span=1mon values(username) as username|mvexpand username|eval month=strftime(_time,"%b")
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

di2esysadmin
Path Finder

This works, but it provides a list of the unique users and all I need is the count. But if I needed the list, this would do it! 🙂

0 Karma

renjith_nair
Legend

ok that was extended. If you replace values(username) by dc(username) in the first search will give you the count

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

javiergn
Super Champion

Is this what you are looking for?

index=main host=nexs*prod* "Searching for user" source="/data/sonatype-work/nexus/logs/nexus.log*" source!="/data/sonatype-work/nexus/logs/nexus.log*.tmp"
| bin _time span=1mon
| stats dc(username) by _time

ppablo
Retired

Hey @di2esysadmin

I see you upvoted this answer, but you didn't accept it. If it did solve your question, please don't forget to resolve the post by clicking "Accept" directly below @javiergn's answer.

0 Karma
Get Updates on the Splunk Community!

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

Get Inspired! We’ve Got Validation that Your Hard Work is Paying Off

We love our Splunk Community and want you to feel inspired by all your hard work! Eric Fusilero, our VP of ...

What's New in Splunk Enterprise 9.4: Features to Power Your Digital Resilience

Hey Splunky People! We are excited to share the latest updates in Splunk Enterprise 9.4. In this release we ...