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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

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

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