Alerting

Table output with Stats command

poddura
Observer

Hi All,

 

I am trying to generate a output using stats command where I want to display table like below

Hostname    FTName       Total      Error Code    Error_Count     Error_rate%

ABC                 some_ft       1000       8945                300                       30.0

I used below query which is giving me output without Error Code, if I add Error_code in stats by command it is giving total count of that error code but I want total to be total request that Ft got and out of that 8945 error code got 300 errors. How to achieve this.

 

index=xyz sourcetype=app_team   log_message.FT=some_ft|rename log_message.CODE as FTCODE|stats count as Total_Requests ,count(eval(FTCODE=="8945")) as Errors by server_host, log_message.FT
| eval Error_rate=round(Errors/Total_Requests*100,2).+"%"|rename log_message.FT as FT

Hostname FT Total_Requests Errors Error_rate

ABCsome_ft259145.41

 

 

 

Labels (1)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @poddura,

le me understand: do you want to execute your search only for one Error_Code (FTCODE)?

if yes, you can add a static eval at the end 

index=xyz sourcetype=app_team   log_message.FT=some_ft
|rename log_message.CODE as FTCODE
| stats count as Total_Requests ,count(eval(FTCODE=="8945")) as Errors by server_host, log_message.FT
| eval Error_rate=round(Errors/Total_Requests*100,2).+"%", FTCODE="8945"
| rename log_message.FT as FT

Yoiu can use the same method also if the error code is passed to the search by an input object.

Ciao.

Giuseppe

 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

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 ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...