Reputation: 8316
I am trying to create an alert based on comparison between few metrics for long running calculations.
Upon competition of batch (which varies in length) I am emitting 2 custom metric: DocsParsedTotal and DocsParsedSuccessful (both values are integers).
I can see those metrics with following query:
customMetrics
| where timestamp >= ago(60m)
| where name == "DocsParsedTotal" or name == "DocsParsedSuccessful"
Is there an option to extend metrics with sum(DocsParsedSuccessful) / sum(DocsParsedTotal) and create alert based on it?
I can also emit a metric for Ratio (per batch) but since my batches varies in length avg() it wont be precise.
Upvotes: 0
Views: 501
Reputation: 30025
It would be better if you can attach an screenshot of the query result in Application Insights -> logs as per the code in your post, like the screenshot in Step 1 of my answer.
And here is an example you can follow, but the data source may be different with yours.
1.The data source in my test:
2.Then you can use the query below:
customMetrics
| where timestamp >= ago(1d)
| where name == "DocsParsedTotal" or name == "DocsParsedSuccessful"
| summarize a2=sumif(value,name=="DocsParsedTotal"),a1=sumif(value,name == "DocsParsedSuccessful")
| extend s1 = iff(a1/a2>2,"alert","not alert")
| where s1 =="alert"
Note of the query:
for this line of code extend s1 = iff(a1/a2>2,"alert","not alert")
, if a1/a2>2
(you can set it to any value instead of 2 as per your need) is true
, then by using where s1 =="alert"
, there should be always 1 result returned. Otherwise, 0 result returned.
3.Next, click the "New alert rule":
4.Then in the "Create rule" page, please follow the steps in screenshot below:
Please let me know if you still have more issues.
Upvotes: 2