Splunk Search

Duration between two events by day based on three or more fields?

nu_learner
Explorer

Hello - I need to calculate the average duration between two status types for a user type in a location in a region. I have attached the sample data. For example, I need to calculate the average duration a given user type remains in "inactive" status. These user types are segregated into different locations in different regions.

Sample data:

nu_learner_0-1678371979630.png

The result is want is like this (time is in seconds):

                   aaa        bbb     ccc
Day 1       30            40        10
Day 2       10            20        30
Day 3        20           10       10

and so on
I would appreciate any help.

Labels (2)
Tags (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

This is nearly one for one the same as https://community.splunk.com/t5/Splunk-Search/Calculate-total-time-for-a-specific-event-over-a-range...; the only difference is that you have consecutive time boundaries you want to calculate for while the other use case calculates for a single start-to-end interval.

 

| eval day = _time
| bin span=1d@d day ``` start of day of event ```
| addinfo ``` search end time is info_max_time ```
| eval duration = if(closed_txn == 1, duration,
 if(status == "active", _time - max(day, info_min_time),
 min(info_max_time, relative_time(day, "+1d")) - _time))
| stats sum(duration) as inactive by day user_type region_id location_id

 

 

Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Your sample data show multiple inactive status for some users. Is this representative or will you only get one event when the state changes?

0 Karma
Get Updates on the Splunk Community!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...