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!

CX Day is Coming!

Customer Experience (CX) Day is on October 7th!! We're so excited to bring back another day full of wonderful ...

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...