Splunk Search

Comparision of hourly Log count by average log count of last 7 days.

phanirohith97
Observer
I have a Query need to compare hourly log count of today with the average value of last 7 days, if the count is greater then it should trigger an alert
Labels (2)
0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @rally0321,

This can be achieved using different approach;

| tstats count where index=some_index earliest=-1d by _time span=1h 
| tstats append=t prestats=t count where index= some_index earliest=-7d@d latest=-1d@d by _time span=1h 
| table _time count psrsvd_gc 
| rename psrsvd_gc AS lastweek_counts 
| eventstats avg(lastweek_counts) as weekly_avg 
| where count>weekly_avg
If this reply helps you an upvote and "Accept as Solution" is appreciated.

rally0321
Path Finder
| tstats count where index=some_index earliest=-1d by _time span=1h 
| tstats append=t prestats=t count where index= some_index earliest=-7d@d latest=-1d@d by _time span=1h 
| table _time count psrsvd_gc 
| rename psrsvd_gc AS lastweek_counts 
| eventstats avg(lastweek_counts) as weekly_avg 
| where count>weekly_avg

Thanks. I can see result with below change.

1. add prestats=t to 1st tstats
2. where count>weekly_avg need change as lastweek_counts>weekly_avg

However I see below gap.

1. the average is the average for the past 1 week + today's count.

2. the result include past 1 week record in case any hour of last week is > average.

We expect to have below result.

1. the average is the average for the past 1 week only

2. the result include today's entry only.

0 Karma

scelikok
SplunkTrust
SplunkTrust

@phanirohith97, please try below query;

| tstats count where index=some_index earliest=-1d by _time span=1h 
| where count > 
    [| tstats count where index=some_index earliest=-7d@d latest=-1d@d by _time span=1h 
    | stats avg(count) as count 
    | rename count as search]
If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma

rally0321
Path Finder
| tstats count where index=some_index earliest=-1d by _time span=1h 
| where count > 
    [| tstats count where index=some_index earliest=-7d@d latest=-1d@d by _time span=1h 
    | stats avg(count) as count 
    | rename count as search]

Hi,

How can we show the average count in the result as well? I refer to value of search. Thanks.

_time                                                count
1 2021-03-04 09:00:00    491

0 Karma
Get Updates on the Splunk Community!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...