How can I create an alert rule that only sends a notification if the CPU usage is over a threshold for X minutes?

Tim Wong 5 Reputation points
2023-10-05T16:56:08.8966667+00:00

I am trying to create an alert rule that is only triggered when our app service exceeds an 80% (max) cpu usage, but ONLY if the threshold is exceeded for 5 minutes. I have gone through the documentation, but some things are not making sense to me:

  1. Is it correct to setup the alert on the app service plan since that holds CPU usage metrics instead of at the app service itself?
  2. Using dynamic thresholds gives me the option of chosing X number of within Y minutes, but the problem is dynamic thresholds won't be triggered looking back at the data. Is there something similar we can do for static thresholds and if so how?
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,850 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,986 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 20,431 Reputation points
    2023-10-11T06:26:50.2466667+00:00

    Tim Wong, thank you for the question.

    Please find below the answer to your question

    1. Yes, you can set the alerting on "App Service Plan" as "CPU %" metrics is available at "App Service Plan" level. App service plans are the set of compute resources in which the App Service instances run. For more details on the available metrics, see App Service Metrics
    2. For your scenario of getting an alert **if "**app service exceeds an 80% (max) cpu usage, but ONLY if the threshold is exceeded for 5 minutes.." - you may use the option available under "When to evaluate". For example, consider the following screenshot:

    User's image

    Based on the settings mentioned in the screenshot above, every 5 minutes, the average of last 5 minutes will be taken for CPU% and if it is >80%, an alert will be generated.

    If you would want to have more analytics-based control, you can enable Diagnostic settings on the App Service plan to route the metrics data to a "Log Analytics" workspace - then a KQL based query can be written to generate an alert based on your requirement. In this case, since you have the flexibility to write the query based on your requirement, this could offer more customization, if the metrics based alert rule does not meet the requirement.

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it, and we will help you out. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.