问题
I'm trying to create an alert for an App Insights custom metric on Azure.
e.g. alert if the "My Metric" metric is greater than 40 for 5 minutes.
According to Custom metrics in Azure Monitor this should be possible.
After they're published to Azure Monitor, you can browse, query, and alert on custom metrics for your Azure resources and applications side by side with the standard metrics emitted by Azure.
I created the metric with this code using the App Insights Python SDK (see Usage).
from applicationinsights import TelemetryClient
tc = TelemetryClient('<YOUR INSTRUMENTATION KEY GOES HERE>')
tc.track_metric('My Metric', 42)
tc.flush()
I can view the custom metric I created. It's the lone blue bar in the screenshot of the Metrics screen in the Azure portal.
However, when I click on the New rule alert button on that screen, I'm taken to the Create rule screen but it displays the following error.
Alerts configuration via Metrics not supported if selection includes multiple resources or more than two metric signals. Please modify your selection and try again or create the rule below. Please click to see the list of supported resources.
AFAIK, I'm only using one resource (the App Insights "Dev" resource) and one metric signal (the "My Metric" metric) as you can see from the screenshot.
Any ideas on what I've done wrong or what I'm missing and how I can correct it?
I'm pretty new to Azure so I'm also open to suggestions on others way of alerting on a custom metric.
回答1:
Please follow the steps below:
- Nav to azure portal -> Monitor -> Metrics -> Add metric. Note that in the dropdown box "METRIC NAMESPACE" -> select azure.applicationinsights under CUSTOM:
- Then in the "METRIC" dropdown box, select your custom metric like "my metric", then click the "New alert rule":
- In the "create rule" page, under CONDITION section, click the link in the screenshot below, then fill in necessary info and click Done button:
回答2:
Another approach to this is to create Alerts based on Analytics query using Custom log search (see also Create, view, and manage log alerts using Azure Monitor) but I prefer the answer I accepted as it's significantly simpler.
来源:https://stackoverflow.com/questions/57803020/cant-create-an-alert-for-an-app-insights-custom-metric-on-azure