Tim Wong, thank you for the question.
Please find below the answer to your question
- 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
- 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:
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.