Splunk Search

Timechart: Unique User of the Last 7 Days

HeinzWaescher
Motivator

Hello,

I would like to create a (time-)chart, that always counts the unique users of the last 7 Days.
For Instance the table should look like this:

07.01.2013 - 1500

08.01.2013 - 2000

09.01.2013 - 2500

The first number means, that there have been 1500 unique users during 01.01.2013 - 07.01.2013.

The second number means, that there have been 2000 unique users during 02.01.2013 - 08.01.2013.

The third number means, that there have been 2500 unique users during 03.01.2013 - 09.01.2013.

It would be great, if somebody could tell me how to do this.

Thanks in advance

Heinz

Tags (1)
0 Karma
1 Solution

kristian_kolb
Ultra Champion

Yes;

sourcetype="blah" 
| timechart span=1d values(userid) as distinct_users 
| streamstats window=7 values(distinct_users) as weekly_users, dc(distinct_users) as weekly_count

Substitute 'userid' with 'clientip' or whatever you have. When you're sure the search is doing what you want, you can remove the values(distinct_users) as weekly_users part of the streamstats command

View solution in original post

HeinzWaescher
Motivator

Hi Kristian,

I checked it again and obviously I made a mistake yesterday. Everthing seems to work fine, even for weeks (window=7) and 30 days (window=30).

Thanks again!

Heinz

0 Karma

HeinzWaescher
Motivator

Hi there,

thanks a lot for your answers. Kristian, I tried out your search and this seems to work fine for the "Last Seven Days". I checked this back for some days in the timechart.

I expected, that a change to "window=30" will calculate the dc of users of the last 30 days. But there are differences, when i check back the results of the timechart. Do you have an idea why this happens?

Best

Heinz

0 Karma

kristian_kolb
Ultra Champion

Yes;

sourcetype="blah" 
| timechart span=1d values(userid) as distinct_users 
| streamstats window=7 values(distinct_users) as weekly_users, dc(distinct_users) as weekly_count

Substitute 'userid' with 'clientip' or whatever you have. When you're sure the search is doing what you want, you can remove the values(distinct_users) as weekly_users part of the streamstats command

kristian_kolb
Ultra Champion

you might want to add an extra line at the end as well;

| fields - distinct_users

to get just the two fields you specified in the output.

0 Karma

somesoni2
Revered Legend

My suggestion would be to create a summary index search which will run daily and store the no of unique users for past 7 days into the summary index. Once this is scheduled and running, you can create your search out of that summary index.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...