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!

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...