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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...