Splunk Search

How do you calculate the total and average duration of the session length for unique users?

tdarrow
New Member

I am relatively new to Splunk so please forgive my naivety.

I have been tasked with calculating the session length of unique users for our lab computers on campus. While my search is far from efficient, I have been able to calculate the duration by session_id (with the help of other questions/answers here).

Now that I have calculated the durations, I would like to calculate the Total Session Length (simple addition of each session length) and the Average Session Length (hours or minutes).

My search string is below. Feel free to help me clean it up where necessary. I greatly appreciate any help or guidance!

index=desktop "Q218" session_id=* Account_Domain=WIN NOT host=MET_IMG NOT user=lab NOT user=PanAgent-svc EventCode=4647 OR EventCode=4624 OR EventCode=4634 | dedup _time user | stats earliest(_time) AS earliest latest(_time) AS latest BY session_id | eval duration = tostring((latest-earliest), "duration") | table user session_id earliest latest duration| where duration>"00:00:00"
0 Karma

tiagofbmm
Influencer

Not sure if you'd want that per user, but here it goes:

index=desktop "Q218" session_id=* Account_Domain=WIN NOT host=MET_IMG NOT user=lab NOT user=PanAgent-svc EventCode=4647 OR EventCode=4624 OR EventCode=4634
| dedup _time user
| stats earliest(_time) AS earliest latest(_time) AS latest BY session_id
| eval duration = tostring((latest-earliest), "duration"), length_seconds=(latest-earliest)
| table user session_id earliest latest duration
| where duration>"00:00:00"
| stats sum(length_seconds) as Total_Length, avg(length_seconds) as Avg_Length by user
| eval Avg_Length_Minutes=Avg_Length/60

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

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 ...