Splunk Search

subtracting 2 timestamps and then evaluating if that result is longer than 1 hour

samnew4598
Explorer

I have two timestamps that are in this format within my log events:

start: 2005-07-05T04:28:34.453494Z

end: 2005-07-05T05:28:39.462681Z

I would like to subtract the timestamps then evaluate them to see if the result is greater or equal to 1 hour and include that event in my query results

Extra:

if so how long?

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex "start: (?<start>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| rex "end: (?<end>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| eval start=strptime(start,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval end=strptime(end,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval diff=end-start
| where diff>=(60*60)
| fieldformat diff=tostring(diff,"duration")

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| rex "start: (?<start>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| rex "end: (?<end>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| eval start=strptime(start,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval end=strptime(end,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval diff=end-start
| where diff>=(60*60)
| fieldformat diff=tostring(diff,"duration")

samnew4598
Explorer

This works great! If you have time can you explain it a bit, I don't know why we need to use "rex" to extract the time? I get the rest of the query as that was one of my initial tries but without the rex. Thanks!

 

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...