Splunk Search

Splunk Query to compute the count of consecutive hourly violations per day

iTechEvent
Explorer

I have data like this...

  • Date - Hour - Sample Number
  • 05/01/2014 - 10 - 200
  • 05/01/2014 - 11 - 201
  • 05/01/2014 - 12 - 202
  • 05/01/2014 - 15 - 205
  • 05/01/2014 - 16 - 206
  • 05/01/2014 - 20 - 210

On 05/01/2014 the max number of consecutive hourly violations i.e. sample 200,201,202 is 3 and occurred between hours 10 to 12.

I have data like this for each day for a month.

I need a splunk query to computer the per day max consecutive hourly violations and the time range between in which it occurred.

Similarly for the entire month I would like the date in which the max number of hourly violations occurred for the month and time range of day.

Any help will be appreciated.

Thanks in advance.

0 Karma
1 Solution

lguinn2
Legend

This solution assumes that your event timestamp (_time) corresponds to the Date and Hour in your events.

yoursearchhere
| transaction Date maxpause=61m
| eval earliestHour=strftime(_time,"%H")
| eval latestHour=strftime(_time+duration,"%H")
| eval errorCount = eventcount
| table Date earliestHour latestHour errorCount
| sort Date -errorCount
| dedup Date

This should work great as long as you have less than 1000 events per Date. Otherwise, Splunk can get a little picky about compiling the transactions - and at that point the solution might start to slow down anyway.

View solution in original post

0 Karma

lguinn2
Legend

This solution assumes that your event timestamp (_time) corresponds to the Date and Hour in your events.

yoursearchhere
| transaction Date maxpause=61m
| eval earliestHour=strftime(_time,"%H")
| eval latestHour=strftime(_time+duration,"%H")
| eval errorCount = eventcount
| table Date earliestHour latestHour errorCount
| sort Date -errorCount
| dedup Date

This should work great as long as you have less than 1000 events per Date. Otherwise, Splunk can get a little picky about compiling the transactions - and at that point the solution might start to slow down anyway.

0 Karma

manish_singh_77
Builder

@lguinn2

I have a query, there is a table where we have the job_result column, if we get consective 5 jobs failed then we need to be alerted.

0 Karma

iTechEvent
Explorer

Awesome lguinn! Works well. Great Insight.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...