Splunk Search

calculate duration between multiple events from same session

sajids
New Member

I am dealing with log files which are structured as follows
TimeStamp=1 SessionHandle=1 SessionEvent=A
TimeStamp=2 SessionHandle=1 SessionEvent=B
TimeStamp=3 SessionHandle=1 SessionEvent=C
TimeStamp=4 SessionHandle=1 SessionEvent=D
TimeStamp=5 SessionHandle=1 SessionEvent=E
TimeStamp=6 SessionHandle=1 SessionEvent=F
TimeStamp=7 SessionHandle=1 SessionEvent=G
TimeStamp=8 SessionHandle=1 SessionEvent=H

TimeStamp=10 SessionHandle=2 SessionEvent=A
TimeStamp=11 SessionHandle=2 SessionEvent=B
TimeStamp=12 SessionHandle=2 SessionEvent=C
TimeStamp=13 SessionHandle=2 SessionEvent=D
TimeStamp=14 SessionHandle=2 SessionEvent=E
TimeStamp=15 SessionHandle=2 SessionEvent=F
TimeStamp=16 SessionHandle=2 SessionEvent=G
TimeStamp=17 SessionHandle=2 SessionEvent=H

I want to calculate duration between various events for each session
For ex: timediff between B & A, similarly H-A, H-D, A-F etc for each session separately and display results in single table

Tags (1)
0 Karma

somesoni2
Revered Legend

You may use streamstats to achieve this. Try something like this

Your Base search | streamstats window=1 current=f first(TimeStamp) as prevTimeStamp | eval duration=prevTimeStamp-TimeStamp 
0 Karma

amitkr0201
Explorer

You can use transaction for this.

e.g. for calculating timediff between A & B, you can use something like

...|transaction SessionHandle startswith="SessionEvent=A" endswith="SessionEvent=B"

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...