Splunk Search

How to extract time interval between each near two events?

JSIrony
Loves-to-Learn Lots

hi, I'm finding how to calculate each time difference from near 2 events

 

for example,

if my search output is

f1    datetime

A     ~~ 09:00

A    ~~ 10:00

A    ~~ 15:00

B    ~~ 06:00

B    ~~ 08:30

 

I want a table like

A 1:00

A 5:00

B 2:30

 

I prefer to print it without making big temporary output table(for look-up or etc) if I can

can I get some ideas?

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming you have the times (_time) in epoch format

| streamstats range(_time) as timediff window=2 global=f by f1
| where timediff>0
| eval timediff=tostring(timediff,"duration")
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Are you looking for delta?

| delta _time as timedelta
0 Karma

JSIrony
Loves-to-Learn Lots

thanks 🙂

 

I considered about delta, but it can't be grouped by another field (like f1 in question i wrote)

 

now I'm trying using streamstats-range-window=2 with time sorted table like this

| streamstats window=2 range(_time) by f1

 

are there other better solutions? 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

If groupby is a requirement (not quite clear in OP), streamstats is the answer.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...