Splunk Search

How to change span alignment

R15
Path Finder

I've tried a few methods shared here to adjust the start/end times of span. Mainly:

1 - 

 

| eval _time=_time-3600
| bin _time span=4h
| eval _time=_time+3600

 

2 -

 

| timechart span=4h aligntime=@h-120m

 

However after testing, neither of these is actually offsetting the span. It only changes the times shown in the resulting table. The values (in my case counts) in each box do not change, just the _time values. Am I doing something wrong?


For example:

_timeABC
1/28 00:00212
1/28 04:00424
1/28 08:00636
1/28 12:00848
1/28 16:0010510

 

_timeABC
1/27 22:00212
1/28 02:00424
1/28 06:00636
1/28 10:00848
1/28 14:0010510
Labels (2)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

With tstats you have to be a bit creative but yes, you can do it. You have to do tstats over finer time division and then aggregate with timechart to a coarser timespan. For example

| tstats prestats=t count where index=something by source _time span=1m
| timechart span=10m aligntime=300 count by source

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

What can I say? The aligntime option works for me. Like

index=firewall earliest=-15m | timechart count span=1m aligntime=30

0 Karma

R15
Path Finder

Does it work with tstats?

0 Karma

PickleRick
SplunkTrust
SplunkTrust

With tstats you have to be a bit creative but yes, you can do it. You have to do tstats over finer time division and then aggregate with timechart to a coarser timespan. For example

| tstats prestats=t count where index=something by source _time span=1m
| timechart span=10m aligntime=300 count by source

R15
Path Finder

This worked great. For anyone else, I verified the totals between the new and old searches just in case with
| addtotals row=f col=t 

Thank you!

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You must have heard the phrase, time is of essence.  This is especially true in time series such as Splunk.  Could you start from the beginning and describe your use case?  What is the input, what is the expected output, and what is the logic between input and expected output without SPL?

0 Karma

R15
Path Finder

I'm searching for a method for general use that I can apply as needed. Currently for testing I'm using a simple tstats search counting events by ip, in spans of 4 hours. I need a way to adjust the starting point of the spans but as shown above, it's not actually shifting where it's searching the data. It's just changing the time labels in the table. 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Always, always describe your use case in terms of data.  Without data, it is very difficult for another person to understand what you are trying to achieve.  Let me give you a starter.

Suppose your raw data is

ABC_time
1382992025-02-04 23:59:00
2362962025-02-04 23:56:00
3342912025-02-04 23:51:00
4322842025-02-04 23:44:00
5302752025-02-04 23:35:00
6282642025-02-04 23:24:00
7262512025-02-04 23:11:00
8242362025-02-04 22:56:00
9222192025-02-04 22:39:00
10202002025-02-04 22:20:00
11181792025-02-04 21:59:00
12161562025-02-04 21:36:00
13141312025-02-04 21:11:00
14121042025-02-04 20:44:00
1510752025-02-04 20:15:00
168442025-02-04 19:44:00
176112025-02-04 19:11:00
184-242025-02-04 18:36:00
192-612025-02-04 17:59:00
200-1002025-02-04 17:20:00
21-2-1412025-02-04 16:39:00
22-4-1842025-02-04 15:56:00
23-6-2292025-02-04 15:11:00
24-8-2762025-02-04 14:24:00
25-10-3252025-02-04 13:35:00

This mock sequence spans roughly three 4-hour intervals.  Now, if you bucket the sequence into 4-hour bins,

 

| bin _time span=4h@h

 

You get

ABC_time
1382992025-02-04 20:00
2362962025-02-04 20:00
3342912025-02-04 20:00
4322842025-02-04 20:00
5302752025-02-04 20:00
6282642025-02-04 20:00
7262512025-02-04 20:00
8242362025-02-04 20:00
9222192025-02-04 20:00
10202002025-02-04 20:00
11181792025-02-04 20:00
12161562025-02-04 20:00
13141312025-02-04 20:00
14121042025-02-04 20:00
1510752025-02-04 20:00
168442025-02-04 16:00
176112025-02-04 16:00
184-242025-02-04 16:00
192-612025-02-04 16:00
200-1002025-02-04 16:00
21-2-1412025-02-04 16:00
22-4-1842025-02-04 12:00
23-6-2292025-02-04 12:00
24-8-2762025-02-04 12:00
25-10-3252025-02-04 12:00

If you do stats/timechart on this, you get what you get.

Now, what do you mean by "adjust the starting point of the spans"?  What will the bucketed sequence look like?  Give a concrete example using this dataset.

You can reproduce the above sequence using the following code:

 

| makeresults count=25
| streamstats count as A
| eval _time = strptime("2025-02-05", "%F") - 60 * A * A
| eval B = 40 - 2 * A, C = 300 - A * A
| bin _time span=4h@h

 

 

R15
Path Finder

Refer to the tables in my original post. I'm doing a count of events per each span using tstats.  So just how many events were there from 00:00-04:00, 04:00-08:00 etc. But splunk chooses that starting point of 00:00 and sometimes it's a very poor choice so I would like to be able to adjust it. So instead it would be 01:00-05:00, 05:00-09:00 etc. The methods I've found in the forum do not seem to work with tstats. As shown in my second table, the _time labels are adjusted but the values are not recalculated. 

0 Karma
Get Updates on the Splunk Community!

Index This | How many sides does a circle have?

  March 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

New This Month - Splunk Observability updates and improvements for faster ...

What’s New? This month, we’re delivering several enhancements across Splunk Observability Cloud for faster and ...

What's New in Splunk Cloud Platform 9.3.2411?

Hey Splunky People! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2411. This release ...