Dashboards & Visualizations

Inactive users vs active users in the last 30 days

rajkskumar
Explorer

I want to build a Chart with two values. Inactive Users based on Customer ID and the Active Users who have used the service in the last 30 days.

 

 

index=prod  earliest=-30d AND latest=now
| eval Total = mvdedup(customerId)
| timechart span=1d dc(customerId) as "Active Users"

 

 

The above code gives me the Chart for Active Users in the last 30 days. From All time data I want to get the count of Total Users and then derive the Inactive users. (Inactive = Total users - Active users). Please help me to rewrite the query to generate the required data.

Labels (1)
0 Karma
1 Solution

FrankVl
Ultra Champion

This (ran over all-time) would get you a list of users and their status (Inactive/Active):

index=prod 
| stats latest(_time) as last_seen by customerId
| eval status = if(last_seen > relative_time(now(), "-30d@d"),"Active","Inactive")

I'm not entirely sure what the end result is that you are after, but hope this helps you in the right direction.

View solution in original post

FrankVl
Ultra Champion

This (ran over all-time) would get you a list of users and their status (Inactive/Active):

index=prod 
| stats latest(_time) as last_seen by customerId
| eval status = if(last_seen > relative_time(now(), "-30d@d"),"Active","Inactive")

I'm not entirely sure what the end result is that you are after, but hope this helps you in the right direction.

rajkskumar
Explorer

Hi @FrankVl,

Thank you very much for your support. This is working as expected. However, I need to add another condition to the "if" clause and I tried with the following. All the users are shown as "Inactive". Could you please point out the issue in the conditions?

index=prod 
| stats latest(_time) as last_seen by customerId, processName
| eval status = if(processName=="Execution" AND (last_seen > relative_time(now(), "-30d@d")),"Active","Inactive")


index=prod 
| stats latest(_time) as last_seen by customerId
| eval status = if(match(processName,"Execution") AND (last_seen > relative_time(now(), "-30d@d")),"Active","Inactive")
0 Karma

FrankVl
Ultra Champion

In the second query, the processName field doesn't exist after the stats command, so you can't use that in the condition.

I'm not sure why the first query doesn't work. Best to investigate it by removing the eval line and look at the results of the stats command, to see if the data would actually match the condition.

To make the 'last_seen' field human readable (for easier investigation if it is within the last 30d), you can do this (at the very bottom of your query, after doing any evals/conditions that need that field):

| convert ctime(last_seen)
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...