Splunk Search

tstat hourly time span without snapping to hour, relative to start of absolute time range instead

akarollil
Explorer

Hello,

I am trying to collect stats per hour using a data model for a absolute time range that starts 30 minutes past the hour. The query looks something like:

|tstats count, sum(X), sum(Y) FROM datamodel=ZModel BY _time span=1h

I choose a time range using the Date & Time Range picker, but the range starts at 30 minutes past the hour. So say something like Jan 1 16:30 to Jan 2 16:30. The problem I have is that the time 'buckets' in the result snap to the hour, and so the hourly ranges are like 16:00 - 17:00, 17:00 - 18:00 and so forth rather than 16:30 - 17:30, 17:30 - 18:30 and so forth.

Is there anyway to make the time buckets start off relative to the start time specified rather than snap to the hour? I tried using earliest= latest= instead of using the Date & Time Range picker, but that didn't help either.

Labels (1)
0 Karma
1 Solution

scelikok
SplunkTrust
SplunkTrust

Hi @akarollil,

tstats command cannot do it but you can achieve by using timechart command.

Please try below;

| tstats count, sum(X) as X , sum(Y) as Y FROM datamodel=ZModel BY _time span=30m 
| timechart span=1h aligntime=@h+30m sum(count) sum(X) sum(Y)
If this reply helps you an upvote and "Accept as Solution" is appreciated.

View solution in original post

scelikok
SplunkTrust
SplunkTrust

You're welcome @akarollil

Please accept the answer for community.

If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @akarollil,

tstats command cannot do it but you can achieve by using timechart command.

Please try below;

| tstats count, sum(X) as X , sum(Y) as Y FROM datamodel=ZModel BY _time span=30m 
| timechart span=1h aligntime=@h+30m sum(count) sum(X) sum(Y)
If this reply helps you an upvote and "Accept as Solution" is appreciated.

akarollil
Explorer

Thanks a lot @scelikok ! That worked. I think I had seen aligntime but couldn't figure out how to use it with tstats or timechart

0 Karma

akarollil
Explorer

Somebody? Anybody?

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

Ready to make your IT operations smarter and more efficient? Discover how to automate Splunk alerts with Red ...