Splunk Search

How to count the number of events within a dynamic time range? (StartTime + Duration)

mspoerr
Path Finder

Hello,

I have logs with the following fields:
StartTime (which is used as _time)
Duration (in seconds)

The goal now is to count the number of events in the same timerange (_time + duration)

i.e.:

StartTime            | Duration | EventNr
7/2/2015 8:45:00 AM  | 3600     | 1
7/2/2015 8:50:00 AM  | 600      | 2
7/2/2015 8:55:00 AM  | 600      | 3
7/2/2015 9:10:00 AM  | 1200     | 4
7/2/2015 10:00:00 AM | 1200     | 5

Range for Event #1 is from 8:45 to 9:45 -> 4 events in this timerange
Range for Event #2 is from 8:50 to 9:00 -> 2 events
...

Result should be a table:

EventNr | EventCount
1       | 4
2       | 2

...

Thanks,
Mathias

0 Karma
1 Solution

woodcock
Esteemed Legend

You can do this with the concurrency command like this:

... | concurrency duration=Duration output=EventCount

Here is another very "expensive" way to do it but it will work:

... | eval StartTime=_time | eaval EndTime = _time + Duration | map search="search _time>=$StartTime$ AND _time<=$EndTime$ | stats count AS EventCount | eval EventNr=$EventNr$"]

View solution in original post

woodcock
Esteemed Legend

You can do this with the concurrency command like this:

... | concurrency duration=Duration output=EventCount

Here is another very "expensive" way to do it but it will work:

... | eval StartTime=_time | eaval EndTime = _time + Duration | map search="search _time>=$StartTime$ AND _time<=$EndTime$ | stats count AS EventCount | eval EventNr=$EventNr$"]

henrysoon
New Member

Pls using eventstats calculation.

0 Karma

somesoni2
Revered Legend

How many rows that might be processed by the search? How many distinct EventNr can exists?

0 Karma

mspoerr
Path Finder

It's a csv with 3000 events and each event has it's distinct EventNr

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 ...