Splunk Search

How to write a search to calculate the average length of sessions by time?

dgravesa1
New Member

Hi New to Splunk:

Trying to calculate average session lengths ( in time ) for sessions that have failed. And one for sessions that are successful. Below is what i have put together:

index=CCTV streaming_realm=* SessionFailed | bucket span=1m _time | dedup device_id, requested_deliverable | search SessionID="*" | stats range(_time) AS Session_Duration_sec by SessionID | stats avg(Session_Duration_Sec)
Tags (3)
0 Karma

somesoni2
Revered Legend

Try this

index=CCTV streaming_realm=* SessionFailed | stats range(_time) as duration by SessionID | stats avg(duration) as Avg_Session_Duration_Sec

OR

index=CCTV streaming_realm=* SessionFailed | transaction SessionID | stats avg(duration) as Avg_Session_Duration_Sec
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...