Splunk Search

Find time between first and second events grouped - efficiently

noambz
Explorer

Hi,

I am getting events in the form of:

__time, app_name, action,udid

"2013-04-11 23:26:32","nxTomo HK V0.9","game_start","1234"

I wish to group them by udid and find the time in seconds between the first and second event,
even if there are more than 2 events in an group.
The rest of the events should be ignored.

Can someone help me do this efficiently?

Tags (1)
0 Karma
1 Solution

noambz
Explorer

I tried this and it seems to work.

action=app_start | streamstats avg(_time) as prevendtime window=1 current=f global=false by udid | eval timegapsecs=abs(round(_time - prevendtime,0)) | reverse | dedup 1 udid

Can anyone comment on the efficiency or correctness of this?

View solution in original post

0 Karma

noambz
Explorer

I tried this and it seems to work.

action=app_start | streamstats avg(_time) as prevendtime window=1 current=f global=false by udid | eval timegapsecs=abs(round(_time - prevendtime,0)) | reverse | dedup 1 udid

Can anyone comment on the efficiency or correctness of this?

0 Karma

jcoates_splunk
Splunk Employee
Splunk Employee
0 Karma

noambz
Explorer

Not exactly.

Let's say I have 3 app starts. They will all be grouped together and the duration will measure the time between the 1st and 3rd.

If I use maxevents=2. Then the other event will be in a separate group which needs to be discarded somehow.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...