How to create Azure Monitor - Alerts for virtual machine using Azure .Net SDK or Powershell scripts.

Dnyaneshwar Surywanshi 156 Reputation points
2021-07-21T05:15:37.757+00:00

I want to create Azure Monitor - Alerts for virtual machine disk utilization, CPU usage etc.
So Is there any way or any Azure .net sdk which will help me on this.

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,786 questions
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,740 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,085 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,355 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. KarishmaTiwari-MSFT 18,352 Reputation points Microsoft Employee
    2021-07-22T20:50:51.887+00:00

    -You can use the Get-AzMetricDefinition cmdlet to view the list of all metrics available for a specific resource like your VM, as described here

    -Metric alert rules have dedicated PowerShell cmdlets available here:

    Add-AzMetricAlertRuleV2: Create a new metric alert rule or update an existing one.
    Get-AzMetricAlertRuleV2: Get one or more metric alert rules.
    Remove-AzMetricAlertRuleV2: Delete a metric alert rule.

    You will find these resources helpful:

    -Managing log alerts using PowerShell
    https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-log#managing-log-alerts-using-powershell

    -Create, view, and manage activity log alerts by using Azure Monitor
    https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-activity-log#powershell

    -FAQs on VM insights:

    Why are metrics from the guest OS of my Azure virtual machine not showing up in Metrics explorer?
    Platform metrics are collected automatically for Azure resources. You must perform some configuration though to collect metrics from the guest OS of a virtual machine. For a Windows VM, install the diagnostic extension and configure the Azure Monitor sink as described in Install and configure Windows Azure diagnostics extension (WAD). For Linux, install the Telegraf agent as described in Collect custom metrics for a Linux VM with the InfluxData Telegraf agent.

    More FAQs here: https://learn.microsoft.com/en-us/azure/azure-monitor/faq#vm-insights

    -Metrics for the guest operating system (guest OS) which runs in Azure Virtual Machines, Service Fabric, and Cloud Services are NOT listed here. Guest OS metrics must be collected through the one or more agents which run on or as part of the guest operating system. Guest OS metrics include performance counters which track guest CPU percentage or memory usage, both of which are frequently used for auto-scaling or alerting.

    Host OS metrics ARE available and listed in this document. They are not the same. The Host OS metrics relate to the Hyper-V session hosting your guest OS session.

    -Supported metrics with Azure Monitor for Virtual machines can be found here

    Please let me know if you have further questions.

    ----------

    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer.

    0 comments No comments