Splunk Search

Calculate time difference between two events

priya1926
Path Finder

Hi All,

 

I am using the below search to calculate time difference between two events ie., 6006 and 6005

6006 is event start time and 6006 is event stopped time. If we find the difference we will get to know the downtime of the system.

This is what i have tried. To few systems it is right and for few it is wrong.


index="wineventlog" host IN (xxxx) EventCode=6006 OR EventCode="6005" Type=Information
| stats latest(_time) as StartUp by host
| join host
[ search index="wineventlog" host IN (xxxx)
| stats latest(_time) as Shutdown by host ]
| eval difference=StartUp-Shutdown
| eval humanTime = strftime(difference*86400)
| table host humanTime

Thanks in advance 🙂

Labels (3)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

I don't understand the logic of this query.  If either a 6005 or a 6006 is received then it is considered a "startup" and if any other event is received from the same host then it is a "shutdown".  Should one event code indicate a startup and the other a shutdown?

Perhaps this query will help.

 

index="wineventlog" host IN (xxxx) EventCode=6006 OR EventCode="6005" Type=Information
| stats earliest(_time) as Shutdown, latest(_time) as Startup by host
| eval Downtime=tostring(Startup-Shutdown, "duration")
| table host Shutdown Startup Downtime
| fieldformat Shutdown=strftime(Shutdown,"%c")
| fieldformat Startup=strftime(Startup,"%c")

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

I don't understand the logic of this query.  If either a 6005 or a 6006 is received then it is considered a "startup" and if any other event is received from the same host then it is a "shutdown".  Should one event code indicate a startup and the other a shutdown?

Perhaps this query will help.

 

index="wineventlog" host IN (xxxx) EventCode=6006 OR EventCode="6005" Type=Information
| stats earliest(_time) as Shutdown, latest(_time) as Startup by host
| eval Downtime=tostring(Startup-Shutdown, "duration")
| table host Shutdown Startup Downtime
| fieldformat Shutdown=strftime(Shutdown,"%c")
| fieldformat Startup=strftime(Startup,"%c")

 

---
If this reply helps you, Karma would be appreciated.

priya1926
Path Finder

Thanks that helped 🙂

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...