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!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...