Forum Discussion

JanLD8850's avatar
JanLD8850
Copper Contributor
Jun 20, 2024

Azure alert on multipel subscriptions

Hi all,

 

i am not sure if this is the rigt place, but here goes.

 

I am working on creating a monitoring solution, and are trying to create some dynamic alert rules.

I need them to look on a lot of subscriptions, but when use chose scope, you can only chose one subscription.

So i have exported the template and add'ed another subscription in the scopes section, but will it work?

 

This is what the properties section looks like in the template, it is looking on cpu usage over time:

"properties": {
                "description""Dynamic warning on CPU ussage",
                "severity"2,
                "enabled"true,
                "scopes": [
                    "/subscriptions/Sub1",
                    "/subscriptions/Sub2"
                ],
                "evaluationFrequency""PT15M",
                "windowSize""PT1H",
                "criteria": {
                    "allOf": [
                        {
                            "alertSensitivity""High",
                            "failingPeriods": {
                                "numberOfEvaluationPeriods"4,
                                "minFailingPeriodsToAlert"4
                            },
                            "name""Metric1",
                            "metricNamespace""microsoft.compute/virtualmachines",
                            "metricName""Percentage CPU",
                            "operator""GreaterOrLessThan",
                            "timeAggregation""Average",
                            "criterionType""DynamicThresholdCriterion"
                        }
                    ],
                    "odata.type""Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria"
                },
 
Any input is more than welcome 🙂
 
Regards
Jan L Dam

2 Replies

  • Gonzalo's avatar
    Gonzalo
    Copper Contributor

    Hi JanLD8850 

    That's because metrics has that restriction, alerts through metrics are easier to setup but hard to manage on time, because you'll need several rules which will do the same for different scopes. 

     

    You should take a look to azure monitoring with log analytics workspace, this way you can build your own alert rules through KQL, if you need to monitor cpu for 100 vm's you can setup a single rule for all virtual machines in that directory, or just filtered for the scope you need.

     

    Here's an example:

     

    InsightsMetrics 
    | where Origin == "vm.azm.ms" 
    | where Namespace == "Processor" and Name == "UtilizationPercentage" 
    | summarize CPUPercentageAverage = avg(Val) by bin(TimeGenerated, 15m), Computer, _ResourceId 

     

    https://learn.microsoft.com/en-us/azure/azure-monitor/vm/monitor-virtual-machine-alerts#log-search-alert-rules-2

    And another more complex rule:

     

    {
        let RuleGroupTags = dynamic(['Linux']);
        Perf | where ObjectName == 'Processor' and CounterName == '% Idle Time' and (InstanceName in ('_Total,'total'))
        | extend CpuUtilisation = (100 - CounterValue)   
        | join kind=inner hint.remote=left (arg("").Resources
            | where type =~ 'Microsoft.Compute/virtualMachines'
        | project _ResourceId=tolower(id), tags) on _ResourceId
        | project-away _ResourceId1
        | where  (tostring(tags.monitorRuleGroup) in (RuleGroupTags)) 
    }

     

    https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-log-alert-query-samples#query-that-filters-virtual-machines-that-need-to-be-monitored

    Regards,





     

     



    • JanLD8850's avatar
      JanLD8850
      Copper Contributor
      Gonzalo

      Thank you for your reply.

      I have been using the log search version for a while, but am looking in to creating dynamic rules, in hope of getting an alert when something out of the ordinary is happening on the vm.

      I might not be an error if a cpu is running on 95% for an hour everyday, but if it starts to do it on times where it not usualy does it, i want an alert.

      I have found a workarround, with exporting the alertrule template, updaing the scope in the template and redeploy it, that seems to work but it is a bit of a pain when we deploys new subscriptions.

      Regards JanLD

Resources