Splunk Search

How to calculate time difference between two specific events?

aramakrishnan
New Member

I want to be able to calculate the time difference between 2 events, through their timestamps, for a specific serial Number.

Event 1: when segmentID=0 and phase=mapStart
Event 2: when phase=integrationEnd

(where segmentID and phase are fields on Splunk).

I don't want to combine searches but I want to be able to compute them using eval commands.

deviceID="ABCD" | eval field 1= (...when segmentID=0 and phase=mapStart....) | eval field 2=(...when phase=integrationEnd....)| eval difference=field1- field2

...where field 1 and field 2 would be the timestamps for both those events extracted.

I feel like it's a pretty simple scenario but I'm not able to extract time values for the two specific events. Thanks for any help in this regard!!

Tags (2)
0 Karma

aramakrishnan
New Member

I have a new situation where I'm looking at the time difference between the first and the last segment for a specific serial number i.e.,
Event 1: When segmentID=0 and phase=mapStart
Event2: When segmentID=(largest segment value) and phase=mapEnd.

The problem here is that the segment numbers vary according to device, and I want my query to be able to identify the highest segment ID. Here's my altered query but I think the portion highlighted is incorrect.
sourcetype="algorithmjoblog" serialNumber="NTEST0872B" | stats max(segmentId) as lastSeg | transaction startswith=(segmentId=0 phase=mapStart) endswith=(segmentId=lastSeg phase=mapEnd)| table duration

Any corrections/alternatives would help!

0 Karma

somesoni2
Revered Legend

How many output rows you're expecting, just one row per deviceID?? If yes then you can try stats/chart command as well

deviceID="ABCD"  (segmentID=0 and phase=mapStart) OR phase=integrationEnd | chart max(_time) over deviceID by phase | eval duration_in_secs=mapStart - mapEnd
0 Karma

masonmorales
Influencer

I might need sample data for this, but I'll try without. Does this work?

deviceID="ABCD" | transaction startswith=(segmentID=0 phase=mapStart) endswith=(phase=integrationEnd)| table duration
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...