Splunk Search

How can I calculate the timediff based on non-sequential sequence IDs?

khavildar
Explorer

I have a requirement wherein I have to find timedifference of 2 events. Below is an example on the event type:

Host    Time          SeqID      Transaction
a          1:00:00      5               Start
b          1:30:00      7               Start
a          1:45:00      9               Complete
b          2:00:00      14             Complete
a          4:00:00      19             Start
c           4:30:00      23             Start
a          4:45:00       25            Complete

I need to calculate the timedifferences between 'Start' and 'Complete' for every Host using their SeqID.
To translate roughly, its like
concat(hostname,Time@Complete,SeqId@Complete) - concat(hostname,Time@Start,SeqID@Start)
But in the above calculation, i need to ensure the SeqID@Complete is the most numerically nearest one to the SeqID@Start.

Any thoughts / suggestions?

0 Karma
1 Solution

renjith_nair
Legend

Hi @khavildar,

Try this

index="your index"  "your other search terms"|table _time,host,SeqID ,Transaction|sort host,SeqID |streamstats current=f last(_time) as prev by host|eval time_diff=_time-prev|where Transaction="Complete"|table host,SeqID ,time_diff
Happy Splunking!

View solution in original post

renjith_nair
Legend

Hi @khavildar,

Try this

index="your index"  "your other search terms"|table _time,host,SeqID ,Transaction|sort host,SeqID |streamstats current=f last(_time) as prev by host|eval time_diff=_time-prev|where Transaction="Complete"|table host,SeqID ,time_diff
Happy Splunking!

khavildar
Explorer

Works like a charm! Perfect.
Thanks so much!

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...