Splunk Search

How to calculate the delta between two time intervals for sending messages?

metylkinandrey
Communicator

Good afternoon! We receive messages on splunk.

The task is as follows: there is a time period between the first message and the second, and also between the second and the third. The task is that you need to somehow calculate the delta between these intervals and display it on the dashboard. This is real? And the question is, how can I do this? Is there a rough example? Unfortunately, I have not worked with splunk at all before, so I don’t even know where to start. If you need leading questions, I'm ready to answer.

Labels (1)
Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

Try something like this (runanywhere sample, change first one with your base search)

index = _internal sourcetype=splunk_web_access 
|  table _time 
|  delta _time as timediff 

  

View solution in original post

somesoni2
Revered Legend

Try something like this (runanywhere sample, change first one with your base search)

index = _internal sourcetype=splunk_web_access 
|  table _time 
|  delta _time as timediff 

  

metylkinandrey
Communicator

Adding "| delta _time as timediff"" in my query:

```

index="bl_logging" sourcetype="testsystem-2"
| transaction maxpause=5m srcMsgId Correlation_srcMsgId messageId
| table _time srcMsgId Correlation_srcMsgId messageId duration eventcount
| delta _time as timediff

```

Works great! Thanks a lot!

But as it turned out, my task is a little more difficult.

delta _time as timediff - works great with messages that arrive sequentially, but there is one problem: messages arrive chaotically from different sources. As it turned out, I need to calculate the delta from messages in one thread. Messages in the same thread have a common srcMsgId (not different as I thought), but each message has an individual messageId. Thus, I need the message threads to be grouped by srcMsgId, and the delta is calculated from the messages strictly in this thread (group). Calculate the interval between the first and second messages in the group, the second and third, etc.

Perhaps you know how to edit my request?

 

 

0 Karma

somesoni2
Revered Legend

There might not be an efficient way to do that. You'll have to sort your data by srcMsgId (and time) and then use Delta.

Or you can use following streamstats version of performing the same.

index="bl_logging" sourcetype="testsystem-2"
| transaction maxpause=5m srcMsgId Correlation_srcMsgId messageId
| table _time srcMsgId Correlation_srcMsgId messageId duration eventcount
| sort srcMsgId _time
| streamstats current=f window=1 values(_time) as prevTime by subject 
| eval timeDiff=_time-prevTime

 

metylkinandrey
Communicator

Yes, it works, thanks a lot!

```

index="bl_logging" sourcetype="testsystem-2"

| transaction maxpause=5m srcMsgId Correlation_srcMsgId messageId

| table _time srcMsgId Correlation_srcMsgId messageId duration eventcount

| sort srcMsgId _time

| streamstats current=f window=1 values(_time) as prevTime by subject

| eval timeDiff=_time-prevTime

| delta _time as timediff

I added: | delta _time as timediff

```

I checked everything works as it should. Thanks again!

 

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...