Splunk Search

Timechart of open sessions per username.

MikhailArefiev
Explorer

I have a file like this:

Time,User-Name,Action
Thu Mar 7 15:09:22,admin,login
Thu Mar 7 17:46:21,admin,login
Thu Mar 7 18:01:33,admin,logout
Thu Mar 7 18:17:23,1111,login
Thu Mar 7 18:37:02,admin,login
Thu Mar 7 19:00:02,admin,logout
Thu Mar 7 19:05:21,admin,logout
Thu Mar 7 20:51:23,1111,logout
Thu Mar 7 21:10:45,admin,logout

I want to plot a timechart of open sessions per each user in the log file. Having read this
and this discussions, I wrote this query:

source="Accounting01" | eval Diff=if(Action="login", 1, if(Action="logout", -1, 0)) | bin _time | stats sum(Diff) as OpenSessions by _time User_Name | streamstats sum(OpenSessions) as OpenSessions by User_Name | eval Str_Time=strftime(_time, "%d-%m-%Y %H:%M:%S") | chart max(OpenSessions) as "Open sessions" by User_Name, Str_Time

This is how it looks now:

timechart.png

The problem is that some of the data is not shown, e. g. there is seemingly 0 sessions for admin between 18:00 and 18:35 while from the data it is obvious that they were logged in the whole time. Same with 1111: they should have 1 session for every point in time until they log out. It is more obviously reflected in the tabular version of the data:

tabular.png

Is it possible to alter the query so that the running sum per each user is stored per each event, even if it is 0 the whole time?


inputs.conf:

[monitor:///home/user/tmp/accounting01.csv]
disabled = false
sourcetype = Acc01
source = Accounting01

props.conf:

[Acc01]
REPORT-rep = Acc01_Fields
TRANSFORMS-skip = Skip_Header

transforms.conf:

[Acc01_Fields]
DELIMS = ","
FIELDS = "Time", "User_Name", "Action"

[Skip_Header]
REGEX = Time,
DEST_KEY = queue
FORMAT = nullQueue
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

How about this?

... | eval Diff=if(Action="login", 1, if(Action="logout", -1, 0)) | reverse | streamstats sum(Diff) as openSessions by User_Name | timechart max(openSessions) by User_Name | filldown

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

How about this?

... | eval Diff=if(Action="login", 1, if(Action="logout", -1, 0)) | reverse | streamstats sum(Diff) as openSessions by User_Name | timechart max(openSessions) by User_Name | filldown

MikhailArefiev
Explorer

Thank you! This is exactly what I was looking for.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...