Splunk Search

How to get stats by hour and calculate percentage for each hour?

bijodev1
Communicator

Hi There,

I am trying to get the an hourly stats for each status code and get the percentage for each hour per status. Not sure how to get it.

my search | 
| bucket _time span=1h
| stats count by _time http_status_code
| eventstats sum(count) as totalCount | eval percentage=round((count/totalCount),3)*100

please suggest which command could be helpful here. 

thanks

Labels (4)
Tags (3)
0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

my_search
| bucket _time span=1h
| stats count BY _time http_status_code
| eventstats sum(count) as totalCount by _time
| eval percentage=round((count/totalCount),3)*100
| table _time http_status_code count percentage

View solution in original post

bijodev1
Communicator

@somesoni2 thank you for the help, it worked.

0 Karma

somesoni2
Revered Legend

Give this a try

my_search
| bucket _time span=1h
| stats count BY _time http_status_code
| eventstats sum(count) as totalCount by _time
| eval percentage=round((count/totalCount),3)*100
| table _time http_status_code count percentage

gcusello
SplunkTrust
SplunkTrust

Hi @bijodev1,

please try this:

my_search
| eventstats sum(count) as totalCount 
| bucket _time span=1h
| stats values(totalCount) AS totalCount count BY _time http_status_code
| eval percentage=round((count/totalCount),3)*100

Ciao.

Giuseppe

0 Karma

bijodev1
Communicator

what I am basically looking for here is 

_time                                 status                           count                                percentage

12:30.                                 100                                 400.                                        30

12:30                                  200                                 600                                         60

12:30                                  300                                 400                                         30

01:30                                  100                                  100                                         10

01:30                                  200                                  400                                          45

01:30                                  300                                  400                                          45

 

like wise

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @bijodev1,

please try this:

my_search
| eventstats count as totalCount 
| bucket _time span=1h
| stats values(totalCount) AS totalCount count BY _time http_status_code
| eval percentage=round((count/totalCount),3)*100

Ciao.

Giuseppe

0 Karma

bijodev1
Communicator

Hi @gcusello 

thank you for the response, but didn't got me any output. 

It doesn't show the percentage and total count per hour

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...