Cloudability Set up Azure Memory Metrics Collection (using Azure Monitoring Agent)

Azure Monitor Agent collects monitoring data from the Azure virtual machines and push it to Azure Monitor.
There are two types of metrics available from Azure Monitor:
  • Standard Metrics: CPU Percentage, Disk Reads/ Writes, Network Throughout
  • Custom Metrics: Memory Utilization

    Install Azure Monitor Agent in Linux

  • In Azure PowerShell , run this command:
    Set-AzVMExtension -Name AzureMonitorLinuxAgent -ExtensionType AzureMonitorLinuxAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true
    Note:

    You can check for latest TypeHandlerVersion . For now the latest is -: 1.20

  • In Azure CLI , run this command:

    az vm extension set --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true

    For further details, refere to https://learn.microsoft.com/en-us/azure/azure-monitor/agents/azure-monitor-agent-manage?tabs=azure-portal

Install Azure Monitor Agent in Windows
  • In Azure PowerShell, run this command:
    Set-AzVMExtension -Name AzureMonitorWindowsAgent -ExtensionType AzureMonitorWindowsAgent -Publisher Microsoft.Azure.Monitor -ResourceGroupName <resource-group-name> -VMName <virtual-machine-name> -Location <location> -TypeHandlerVersion <version-number> -EnableAutomaticUpgrade $true
    Note:

    You can check for latest TypeHandlerVersion . For now the latest is -: 1.20

  • In Azure CLI, run this command:
    az vm extension set --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --ids <vm-resource-id> --enable-auto-upgrade true
    Note:

    For the confirmation of successful agent installation check in the extension of your machine.

Methods to Send Custom Metrics
  1. Install the Azure Diagnostics extension on your Azure VM .
    Note:

    We were using Method 1 to push memory metrics to Azure Monitor as Azure Monitor Agent support was not there

    For reference: Set up Azure Memory Metrics Collection (using Azure Monitor)

  2. Install the Azure Monitor agent on your Windows or Linux Azure VM .
    Note:

    As Azure has provided its support to push custom metric through Azure Monitor Agent, so we can use the below steps for the same.

Send Custom Metrics with Azure Monitor Agent

Reference: https://learn.microsoft.com/en-us/azure/azure-monitor/agents/data-collection-rule-azure-monitor-agent?tabs=portal

Create Data Collection Rule
  1. From the Monitor menu, select Data Collection Rules .
  2. Select Create to create a new data collection rule and associations.
  3. Enter a Rule name and specify a Subscription , Resource Group , Region , and Platform Type.
  4. On the Resources tab:
    • Select + Add resources and associate resources to the data collection rule. Resources can be Virtual Machines, Virtual Machine Scale Sets, and Azure Arc for servers. The Azure portal installs Azure Monitor Agent on resources that don't already have it installed.
    • Select Enable Data Collection Endpoints .
    • Select a data collection endpoint for each of the resources associate to the data collection rule.
  5. On the Collect and deliver tab, select Add data source to add a data source and set a destination.
  6. Select a Data source type .
  7. Select which data you want to collect. For performance counters, you can select from a predefined set of objects and their sampling rate. For events, you can select from a set of logs and severity levels.
  8. On the Destination tab, add one or more destinations for the data source. You can select multiple destinations of the same or different types. For instance, you can select multiple Log Analytics workspaces, which is also known as multihoming.
  9. Select Add data source and then select Review + create to review the details of the data collection rule and association with the set of virtual machines.
  10. Select Create to create the data collection rule.
    Note:

    It can take up to 5 minutes for data to be sent to the destinations after you create the data collection rule.