Last active
November 8, 2018 00:12
-
-
Save tknerr/de41f44f739f50284fb29c2ee11fa131 to your computer and use it in GitHub Desktop.
Show the actual requests of the past 5 minutes vs the average request count over the past day. The threshold we want to alert upon is the past day's average amplified by a factor of 10.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lookbackWindow=30d; | |
let observationInterval=1d; | |
let sampleInterval=5m; | |
let thresholdFactor=10; | |
// 5-min request count average measured over the past 1 day | |
let averagedRequestsInObservationInterval = requests | |
| where timestamp > ago(lookbackWindow) | |
| summarize sum(itemCount) by bin(timestamp, sampleInterval) | |
| summarize averageRequestCount = avg(sum_itemCount) by bin(timestamp, observationInterval) | |
| extend threshold = averageRequestCount * thresholdFactor; | |
// actual request count of the last 5 min | |
let actualRequestsInSampleInterval = requests | |
| where timestamp > ago(lookbackWindow) | |
| summarize currentRequestCount = sum(itemCount) by bin(timestamp, sampleInterval); | |
// render | |
actualRequestsInSampleInterval | |
| union averagedRequestsInObservationInterval | |
| render timechart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improved and simpler version is here, making use of series_fir() to compute the moving average:
The result looks much better now: