Splunk Search

Getting counts of each search result over time

chadwell
Explorer

I am trying to determine a way to search for user logins over time to get an idea of application usage.

If I have a set number of user ids, I want to get a count of their logins based on a search string in our logs.

So my search is like this:

"Looking for user based on login/user_id=" "abc123" OR "zxy987"

So this would give me all the logs where each of these users had attempted to login and use the application, it could be multiple times per day and there could be multiple entries per day per user of this search string.

But I would like to chart this on a dashboard with time on the x-axis and individual 'string search match" count aka login count on the y axis.

How would I accomplish this in splunk? Would I need to change my search?

Tags (3)
0 Karma
1 Solution

somesoni2
Revered Legend

We probably need to look at your raw data to give you accurate suggestion. Here is my attempt without that (assuming user is appear in raw log after string /user_id=. Also recommend adding one or more metadata fields index/sourcetype/host/source in your query for better performance)

index=foo sourcetype=bar "Looking for user based on login/user_id=" "abc123" OR "zxy987"
| rex "login/user_id=(?<user_id>\S+)" 
| timechart count by user_id

View solution in original post

chadwell
Explorer

Thanks for your reply. This is great and works well.
I can now see a table of all the counts per day for each user id.

I have a final question, if I wanted to modify the query to show only the days where a user had logged in and not care about the actual count per day, but only be interested if there was a match per day.

The heatmap looks like a good chart for this, where I can have a color where the user logged in and where a user didn't. Then at the bottom of a table it would be good to have a count of the number of days the user logged in (that is, if they log in 3 times in 1 days just count that as 1).

I hope that makes sense and thanks for you help.

0 Karma

somesoni2
Revered Legend

We probably need to look at your raw data to give you accurate suggestion. Here is my attempt without that (assuming user is appear in raw log after string /user_id=. Also recommend adding one or more metadata fields index/sourcetype/host/source in your query for better performance)

index=foo sourcetype=bar "Looking for user based on login/user_id=" "abc123" OR "zxy987"
| rex "login/user_id=(?<user_id>\S+)" 
| timechart count by user_id
Get Updates on the Splunk Community!

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...

Cloud Platform & Enterprise: Classic Dashboard Export Feature Deprecation

As of Splunk Cloud Platform 9.3.2408 and Splunk Enterprise 9.4, classic dashboard export features are now ...