Splunk Search

The output of the tstats command won't work for trellis charts, only stats... why?

murdermostfowl
New Member

I really like the trellis feature for bar charts. It works great when I work from datamodels and use stats. However, when I use the tstats command to get better performance, even though the data appears be be exactly the same in the statistics tab, it does not render properly in Visualizations unless you redundantly pass it through stats:

| tstats summariesonly=true count from datamodel="Network_Traffic.All_Traffic" where All_Traffic.dest_port=22 by All_Traffic.dvc, All_Traffic.action 
| rename All_Traffic.dvc as Device, All_Traffic.action AS Action 

This does not work. This, however does work:

 tstats summariesonly=true count from datamodel="Network_Traffic.All_Traffic" where All_Traffic.dest_port=22 by All_Traffic.dvc, All_Traffic.action 
    | rename All_Traffic.dvc as Device, All_Traffic.action AS Action 
    |  stats sum(count) by Device, Action

( Then apply the visualization bar (or column) chart, independent scale, trellis, split by Device. )

The data output is visually identical, but I get the strong feeling there is a hidden datatype that stats is outputting that I can't see. The visualization shows the data as an aggregation and gives no other choices, but when you apply the stats, it suddenly recognizes 3 different things to split by. Whatever this secret formatting method is, is there a faster/more direct function to properly convert the fields so that you don't have to do this redundant stats command?

Thanks!

0 Karma
1 Solution

sduff_splunk
Splunk Employee
Splunk Employee

You will need to use prestats mode with tstats, see https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Tstats

| tstats prestats=true summariesonly=true count from datamodel="Network_Traffic.All_Traffic" where All_Traffic.dest_port=22 by All_Traffic.dvc, All_Traffic.action 
| rename All_Traffic.dvc as Device, All_Traffic.action AS Action 
|  stats sum(count) by Device, Action

View solution in original post

0 Karma

sduff_splunk
Splunk Employee
Splunk Employee

You will need to use prestats mode with tstats, see https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Tstats

| tstats prestats=true summariesonly=true count from datamodel="Network_Traffic.All_Traffic" where All_Traffic.dest_port=22 by All_Traffic.dvc, All_Traffic.action 
| rename All_Traffic.dvc as Device, All_Traffic.action AS Action 
|  stats sum(count) by Device, Action
0 Karma

murdermostfowl
New Member

Thank you, this worked!

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...