Splunk Search

How to get the maximum count by host and time

spkriyaz
Path Finder

Hi,

I am trying to query to pick the maximum TPS count of each host(three hosts) and the time when the maximum count was reported. There maybe many instance where the count will be same for more than one time, in that case I would chose the count for the latest time. The below query picks the maximum count per host but I am unable to write the time when it was maximum.

 

index= xyz 
| timechart span=1s cont=false count BY host_name 
| untable _time host_name count
| stats max(count) as count BY host_name

 

So I need help to know how to include the _time with my output(as I said count might be same for different time in that case I need the latest time written to the output along with host and maximum count)
OUTPUT:

Capture.JPG

Labels (2)
Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index= xyz 
| bin span=1s _time
| stats count BY host_name, _time
| eventstats max(count) as max BY host_name
| where count=max
| stats values(count) as count, latest(_time) as _time by host_name
| fields host_name, count, _time

Good point - just add _time to the first stats (I forgot to add it after changing from timechart to stats)

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

You could try something like

index= xyz 
| bin span=1s _time
| stats count BY host_name 
| eventstats max(count) as max BY host_name
| where count=max
| stats values(count) as count, latest(_time) as _time by host_name
| fields host_name, count, _time

 

0 Karma

spkriyaz
Path Finder

It won't work as the query is not picking the maximum count of each second(Transaction per second for each host), it does the overall count and the _time is not considered in the initial stats so the _time is not considered anywhere down the line

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index= xyz 
| bin span=1s _time
| stats count BY host_name, _time
| eventstats max(count) as max BY host_name
| where count=max
| stats values(count) as count, latest(_time) as _time by host_name
| fields host_name, count, _time

Good point - just add _time to the first stats (I forgot to add it after changing from timechart to stats)

Get Updates on the Splunk Community!

Fueling your curiosity with new Splunk ILT and eLearning courses

At Splunk Education, we’re driven by curiosity—both ours and yours! That’s why we’re committed to delivering ...

Splunk AI Assistant for SPL 1.1.0 | Now Personalized to Your Environment for Greater ...

Splunk AI Assistant for SPL has transformed how users interact with Splunk, making it easier than ever to ...

Unleash Unified Security and Observability with Splunk Cloud Platform

     Now Available on Microsoft AzureOn Demand Now Step boldly into the AI revolution with enhanced security ...