Splunk Search

TIme difference between first and last

darkins
Engager

My query returns these events, i need to compute the total time A was in this state and total time B was in this state. My thought is to subtract the TImestamp of the first A from the most recent A and so on for B but cant figure out the right way to do this?

 

TimestampJobDateLoggedTimeReady
1728092168.000000A10/4/202421:36:031
1728092163.000000A10/4/202421:35:501
1728092150.000000A10/4/202421:35:271
1728092127.000000A10/4/202421:35:161
1728090335.000000B10/4/202421:05:152
1728090315.000000B10/4/202421:05:032
1728090303.000000B10/4/202421:04:532
1728090293.000000B10/4/202421:04:312
Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming the timestamp you want is in _time,  you could use transaction to get the duration

| transaction Job

If not, you could reassign the _time field to be the time you want.

0 Karma

PickleRick
SplunkTrust
SplunkTrust

But since transaction is one of the cursed commands 😉 you can - assuming Job is unique - do

| stats min(_time) as start max(_time) as end by Job
| eval duration=end-start
0 Karma

darkins
Engager

ok this should work but one wrinkle, i want to do this on two fields meaning:

these are my records

Job110/4/20242024100410/4/20240:38:27 
Job110/4/20242024100410/4/20240:38:41 
Job 210/4/20242024100410/4/202417:39:12 
Job 210/4/20242024100410/4/202417:39:24 
Job 210/4/20242024100410/4/202417:39:34 
Job110/5/20242024100410/4/20240:38:27 
Job110/5/20242024100410/4/20240:38:35 

 

from this i want to be able to say:

job1 took 14 seconds on 10/4/2024 and job 2 took 22 seconds on 10/4

job 1 took 8 seconds on 10/5

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You mean something like this?

 

| eval date = strftime(_time, "%F")
| stats min(_time) as start max(_time) as end by date
| eval duration = round(end - start)
| fields - start end

 

dateduration
2024-10-0461267
2024-10-058

Here is the emulation

 

| makeresults format=csv data="jobId, date, skip1, skip2, time
Job1,	10/4/2024,	20241004,	10/4/2024,	0:38:27	 
Job1,	10/4/2024,	20241004,	10/4/2024,	0:38:41	 
Job 2,	10/4/2024,	20241004,	10/4/2024,	17:39:12	 
Job 2,	10/4/2024,	20241004,	10/4/2024,	17:39:24	 
Job 2,	10/4/2024,	20241004,	10/4/2024,	17:39:34	 
Job1,	10/5/2024,	20241004,	10/4/2024,	0:38:27	 
Job1,	10/5/2024,	20241004,	10/4/2024,	0:38:35"
| eval _time = strptime(date . " " . time, "%m/%d/%Y %H:%M:%S")
``` data emulation above ```

 

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!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...