Splunk Search

How can I count account access to devices (counts) by day?

pyamamoto
New Member

I want to find/graph the count of (dc(X) as dc_X_count by Y) by day.

In other words, I have some events in a basic search with two id's X and Y. There are 1 or more X values per Y. The max number of X/Y is reasonable (like say < 50/day).

But what I want to know is how many of each number of X/Y's is happening per day. Example use case, X is an account id, Y is a device id. We can have multiple accounts logging into the same device. So I want to find the count of #ofaccounts/device each day (eg 100 devices have 1 account logging in, 50 devices have 2 accounts logging in, etc).

to get the initial pass of data it looks like

search for login events containing accountid(X), deviceid(Y) ... | timechart span=1d dc(accountid) as accounts_count by deviceid

but then I don't know how to get a count of those results by day.

0 Karma
1 Solution

elliotproebstel
Champion

Not sure if this is the best approach, but I think it will work:
search for login events
| bin _time span=1d as day
| stats dc(accountid) as account_count BY day deviceid
| stats dc(deviceid) AS device_count BY day account_count

View solution in original post

0 Karma

elliotproebstel
Champion

Not sure if this is the best approach, but I think it will work:
search for login events
| bin _time span=1d as day
| stats dc(accountid) as account_count BY day deviceid
| stats dc(deviceid) AS device_count BY day account_count

0 Karma

pyamamoto
New Member

Clever! That seems to work to generate statistics. but I'm now failing to be able to chart that by day.

0 Karma

DalJeanis
SplunkTrust
SplunkTrust

@pyamamoto - Changing both those stats to eventstats is a little scary to me, since I can't picture whether the results is mathematically accurate. I suspect that it is, but you are making the computer work a lot harder than it needs to, fully scanning the entire result set three times when each scan could be reducing the results for its successor.

All you really need to do to get the timechart to work is add this to the end of @elliotproebstels code...

| rename day as _time
| timechart span=1d max(device_count) by account_count

You could also use max(), min(), values(), avg(), last(), first() or whatever reasonable aggregate function you want, since there is only one answer per day, they all will get the same answer.

0 Karma

pyamamoto
New Member

Thank you for the feedback. I hadn't seen that mentioned before: rename day as _time to be able to use timechart. That helps a lot.

0 Karma

pyamamoto
New Member

I changed stats to eventstats and then I could send to| timechart span=1d max(device_count) by account_count

0 Karma

elliotproebstel
Champion

Great! Smart fix.

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...