'Regarding custom metrics application insights

I have a scenario where I'm getting custom metrics thru an application. I want to create alerts based on thresholds and days of the week. Is there any way I can integrate the metadata in some storage and compare the metrics based on that? For example, I have message count metrics in the application, and if on Monday the message count is less than 100 or more than 200 I should get an alert. It varies on the day of the week. I have to monitor almost 250 custom metrics.

I tried implementing custom logs in Log analytics but I have a challenge in case if I want to change the thresholds then I need to drop the custom table and recreate it.



Solution 1:[1]

Thank you AnuragSingh-MSFT | Microsoft Docs. Posting your suggestion as an answer to help other community members.

Using a combination of both dayofweek() and case() functions, the resultant query itself can contain the threshold based on the day-of-week. Therefore, in future if the threshold changes, you will only have to edit the case statement and this solution also does not require additional storage/custom table.

let day = dayofweek(now());
let threshold = case(day == 1d, 5m,  //threshold for Monday is 5 minutes
day == 2d, 2m, //threshold for Tuesday is 2 minutes
day == 3d, 5s, //threshold for Wednesday is 5 seconds
10m); //threshold for any other day is 10 minutes.

Heartbeat
| summarize LastHeartbeat=max(TimeGenerated) by Computer
| where LastHeartbeat < ago(threshold)  

Reference: Regarding custom metrics application insights - Microsoft Q&A

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MadhurajVadde-MT