Splunk Search

How to get total number of hours elapsed from last event raised till now()?

sjs
Path Finder

Hey people,

I want to find out the total number of hours that elapsed from the last event raised.

 

This is what I was doing previously:

 

 

| stats latest(_time) as last_log_time  | eval timeElapsedSinceLastLog=tostring(now() - last_log_time) | fieldformat timeElapsedSinceLastLog = strftime(timeElapsedSinceLastLog, "%H:%M:%S") |fields timeElapsedSinceLastLog

 

 

 

 

this gives me

sjs_0-1674454009705.png

 

But it has been more than a week, since the last event raised

 

I am also happy, if I could get number of days elapsed with time(if days < 1) as well.

Labels (1)
0 Karma
1 Solution

manjunathmeti
Champion

hi @sjs ,

You can divide the elapsed time with 86400 to get the number of days, try this:

 

| stats latest(_time) as last_log_time 
| eval timeElapsedSinceLastLog=now() - last_log_time, days=round(timeElapsedSinceLastLog/86400, 0) 
| eval timeElapsedSinceLastLog = strftime(timeElapsedSinceLastLog, "%H:%M:%S") 
| eval timeElapsedSinceLastLog=if(days > 0, days." days, ".timeElapsedSinceLastLog, timeElapsedSinceLastLog) 
| fields timeElapsedSinceLastLog

 

View solution in original post

manjunathmeti
Champion

hi @sjs ,

You can divide the elapsed time with 86400 to get the number of days, try this:

 

| stats latest(_time) as last_log_time 
| eval timeElapsedSinceLastLog=now() - last_log_time, days=round(timeElapsedSinceLastLog/86400, 0) 
| eval timeElapsedSinceLastLog = strftime(timeElapsedSinceLastLog, "%H:%M:%S") 
| eval timeElapsedSinceLastLog=if(days > 0, days." days, ".timeElapsedSinceLastLog, timeElapsedSinceLastLog) 
| fields timeElapsedSinceLastLog

 

Get Updates on the Splunk Community!

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...

Adoption of Infrastructure Monitoring at Splunk

  Splunk's Growth Engineering team showcases one of their first Splunk product adoption-Splunk Infrastructure ...

Modern way of developing distributed application using OTel

Recently, I had the opportunity to work on a complex microservice using Spring boot and Quarkus to develop a ...