Splunk Search

How do I find the time difference between these two events?

tomaszwrona
Explorer

Hello,

I have following events:

event 1:

product_category=dvd
product_name="the martian"
event=to_basket
event_time=2016-01-18T19:57:21+0100
...

event2:

product_category=dvd
product_name="the martian"
event=sold
event_time=2016-01-18T20:15:21+0100
...

How can I tell the time difference between 'to_basket' and 'sold' based on product_category and product_name?

0 Karma
1 Solution

somesoni2
Revered Legend

Try something like this

your base search giving above two type of events i.e. event=to_basket OR event=sold | stats values(event_time) as event_time values(event) as event by product_category, product_name | eval Diff=strptime(mvindex(event_time,0),"%Y-%m-%dT%H:%M:%S%z")-strptime(mvindex(event_time,-1),"%Y-%m-%dT%H:%M:%S%z")

View solution in original post

somesoni2
Revered Legend

Try something like this

your base search giving above two type of events i.e. event=to_basket OR event=sold | stats values(event_time) as event_time values(event) as event by product_category, product_name | eval Diff=strptime(mvindex(event_time,0),"%Y-%m-%dT%H:%M:%S%z")-strptime(mvindex(event_time,-1),"%Y-%m-%dT%H:%M:%S%z")

tomaszwrona
Explorer

Perfect, thank you!

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 ...