Splunk Search

How do I create a timechart with spans that aren't aligned to the start of a minute/hour/day etc?

lukemundy
New Member

I'm using timechat to count the number of events per minute in a single value display: search | timechart span=1m count

This works fine. However, each time span is aligned to the top of the minute, meaning that the single value is only ever accurate when the search is conducted at the top of the minute. I want my single value to display the total number of requests in the last minute from now and not the last whole minute.

For example, if the search is running at 12:15:39, the single value should show the count of events between 12:14:39 and 12:15:39, rather than the count from 12:14:00 to 12:15:00 (or, if using partial=true, 12:15:00 to 12:15:39)

Is timechart suitable for this or do I need to use another method?

0 Karma

woodcock
Esteemed Legend

You can add/remove any arbitrary time-segment like this:

Your Base Search Here
[| makeresults 
 | rename COMMENT AS "This expands the window by 1 minute on each side"
 | addinfo 
 | eval search = "earliest=" . (info_min_time - 60) . " latest=" . (info_max_time + 60)
 | table search]
| timechart count span=1m

DalJeanis
Legend

You can add/subtract an offset, run your timechart, then subtract/add it back.

Here's a run-anywhere example...

 index=_internal earliest=-610s 
| addinfo | eval delay=info_max_time % 60 | eval _time = _time - delay 
| timechart span=1m count  
| addinfo | eval delay=info_max_time % 60 | eval _time = _time + delay | fields - delay info*

Notes

1) timechart kills the calculated field, so you have to do it all over again, then delete the added fields as well.

2) You can use info_max_time or info_min_time, depending on whether you are more concerned about aligning the start of the period or the end of the period. They are functionally equivalent except for edge cases.

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