Splunk Search

How to combine my two tstats searches?

abbam
Explorer

Hi,

Wondering if someone could help me here, I'm trying to join two tstats searches together.

I basically want to get a result 120 minutes ago and a result for the last 60 minutes based on hosts.

Here is the search:

| tstats summariesonly=t prestats=t count as old from datamodel=Web WHERE earliest=-120m latest=-60m by host | stats count as old by host | tstats summariesonly=t prestats=t append=t count as new from datamodel=Web WHERE earliest=-60m latest=now by host | stats count as new by host

Any idea why this doesn't work?

Thanks!

1 Solution

somesoni2
Revered Legend

Try like this

| tstats summariesonly=t prestats=t count from datamodel=Web WHERE earliest=-120m@m latest=@m by host _time span=1m | eval Period=if(_time>relative_time(now(),"-60m@m"),"New","Old") | chart sum(count) over host by Period

View solution in original post

somesoni2
Revered Legend

Try like this

| tstats summariesonly=t prestats=t count from datamodel=Web WHERE earliest=-120m@m latest=@m by host _time span=1m | eval Period=if(_time>relative_time(now(),"-60m@m"),"New","Old") | chart sum(count) over host by Period

abbam
Explorer

Thanks for that.

Afraid it doesn't work. sum(count) has no values, but I know there are numbers there because I can do it without using the datamodel.

0 Karma

MuS
SplunkTrust
SplunkTrust
0 Karma

abbam
Explorer

Managed to fix it by,

| tstats summariesonly=t prestats=t count from datamodel=Matin WHERE earliest=-120m@m latest=@m by host _time span=1m | eval Period=if(_time>relative_time(now(),"-60m@m"),"New","Old") | chart count over host by Period

Thanks!!!!!

0 Karma
Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

New Release | Splunk Cloud Platform 10.1.2507

Hello Splunk Community!We are thrilled to announce the General Availability of Splunk Cloud Platform 10.1.2507 ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...