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!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...