How can I create an alert rule on a custom metric?


  • I have an Application Insights instance to which I send data for a custom metric from a webjob. I want to create an alert rule on this metric. I have tried several times from the portal: each time I get an error message which says just that it failed to create. I'm not allowed to inline the screenshot, but it uploaded ok to .

    The "Demo" rule uses the same Application Insights resource and the same action group, so I think the problem is narrowed down to using a custom metric.

    In the hope of at least getting a more detailed error message, I tried to do the same with the .Net SDK. I fetched the description of Demo to use as a baseline and sniffed a creation attempt with the portal to get the metric namespace, and came up with

                await alertsClient.MetricAlerts.CreateOrUpdateAsync("nath-dev", "queue_length", new MetricAlertResourceInner
                    Description = "One or more of the queues is getting too full. Check that the webjob processing it hasn't failed.",
                    Enabled = true,
                    Severity = 3,
                    Location = "global",
                    WindowSize = TimeSpan.FromMinutes(5),
                    EvaluationFrequency = TimeSpan.FromMinutes(5),
                    Scopes = new string[] { $"/subscriptions/{SubscriptionId}/resourceGroups/nath-dev/providers/microsoft.insights/components/monitor-nath-dev" },
                    Criteria = new MetricAlertSingleResourceMultipleMetricCriteria
                        AllOf = new MetricCriteria[]
                            new MetricCriteria
                                Name = "Metric1",
                                MetricName = "Queue length",
                                MetricNamespace = "Azure.ApplicationInsights",
                                Dimensions = new MetricDimension[0],
                                TimeAggregation = "Maximum",
                                OperatorProperty = "GreaterThan",
                                Threshold = 100
                    Actions = new MetricAlertAction[]
                        new MetricAlertAction
                            ActionGroupId = $"/subscriptions/{SubscriptionId}/resourcegroups/nath-dev/providers/microsoft.insights/actiongroups/email%20tech"

    However, the result was

    HTTP/1.1 500 InternalServerError
    Pragma: no-cache
    x-ms-request-id: ee26393a-e273-4dc2-bfb1-e60dfa692295
    x-ms-failure-cause: service
    x-ms-ratelimit-remaining-subscription-writes: 1199
    x-ms-correlation-request-id: ee26393a-e273-4dc2-bfb1-e60dfa692295
    x-ms-routing-request-id: FRANCESOUTH:20190416T120231Z:ee26393a-e273-4dc2-bfb1-e60dfa692295
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Content-Type-Options: nosniff
    Connection: close
    Cache-Control: no-cache
    Date: Tue, 16 Apr 2019 12:02:31 GMT
    Server: Microsoft-IIS/10.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET

    Since it's returning a 500 rather than a 4xx I understand that the problem is at your end rather than being a badly formed request. Is that correct, or do I need to rework my request?

    • Edited by Peter (NeuroAtHome) Wednesday, April 17, 2019 8:13 AM Clearer separation between reply body and commentary
    Wednesday, April 17, 2019 8:12 AM


All replies