title | description | author | services | ms.service | ms.topic | ms.date | ms.author | ms.component |
---|---|---|---|---|---|---|---|---|
Send Guest OS metrics to the Azure Monitor metric store using a Resource Manager template for a Windows virtual machine |
Send guest OS metrics to the Azure Monitor metric store using a Resource Manager template for a Windows virtual machine |
anirudhcavale |
azure-monitor |
azure-monitor |
howto |
09/24/2018 |
ancav |
metrics |
Send Guest OS metrics to the Azure Monitor metric store using a Resource Manager template for a Windows virtual machine
By using the Azure Monitor Diagnostics extension, you can collect metrics and logs from the guest operating system (Guest OS) that's running as part of a virtual machine, cloud service, or Service Fabric cluster. The extension can send telemetry to many different locations.
This article describes the process for sending Guest OS performance metrics for a Windows virtual machine to the Azure Monitor data store. Starting with Diagnostics version 1.11, you can write metrics directly to the Azure Monitor metrics store, where standard platform metrics are already collected.
Storing them in this location allows you to access the same actions for platform metrics. Actions include near-real time alerting, charting, routing, and access from a REST API and more. In the past, the Diagnostics extension wrote to Azure Storage, but not to the Azure Monitor data store.
If you're new to Resource Manager templates, learn about template deployments and their structure and syntax.
-
Your subscription must be registered with Microsoft.Insights.
-
You need to have either Azure PowerShell or Azure Cloud Shell installed.
The Azure Diagnostics extension uses a feature called "data sinks" to route metrics and logs to different locations. The following steps show how to use a Resource Manager template and PowerShell to deploy a VM by using the new "Azure Monitor" data sink.
For this example, you can use a publicly available sample template. The starting templates are at https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-simple-windows.
-
Azuredeploy.json is a preconfigured Resource Manager template for the deployment of a virtual machine.
-
Azuredeploy.parameters.json is a parameters file that stores information such as what user name and password you would like to set for your VM. During deployment, the Resource Manager template uses the parameters that are set in this file.
Download and save both files locally.
Open the azuredeploy.parameters.json file
-
Enter values for adminUsername and adminPassword for the VM. These parameters are used for remote access to the VM. To avoid having your VM hijacked, DO NOT use the values in this template. Bots scan the internet for user names and passwords in public Github repositories. They are likely to be testing VMs with these defaults.
-
Create a unique dnsname for the VM.
Open the azuredeploy.json file
Add a storage account ID to the variables section of the template after the entry for storageAccountName.
// Find these lines.
"variables": {
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'sawinvm')]",
// Add this line directly below.
"accountid": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
Add this Managed Service Identity (MSI) extension to the template at the top of the resources section. The extension ensures that Azure Monitor accepts the metrics that are being emitted.
//Find this code.
"resources": [
// Add this code directly below.
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "WADExtensionSetup",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" ],
"properties": {
"publisher": "Microsoft.ManagedIdentity",
"type": "ManagedIdentityExtensionForWindows",
"typeHandlerVersion": "1.0",
"autoUpgradeMinorVersion": true,
"settings": {
"port": 50342
}
}
},
Add the identity configuration to the VM resource to ensure that Azure assigns a system identity to the MSI extension. This step ensures that the VM can emit guest metrics about itself to Azure Monitor.
// Find this section
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
// add these 3 lines below
"identity": {
"type": "SystemAssigned"
},
//end of added lines
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
...
Add the following configuration to enable the Diagnostics extension on a Windows virtual machine. For a simple Resource Manager-based virtual machine, we can add the extension configuration to the resources array for the virtual machine. The line "sinks"— "AzMonSink" and the corresponding "SinksConfig" later in the section—enable the extension to emit metrics directly to Azure Monitor. Feel free to add or remove performance counters as needed.
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob]"
}
}
},
//Start of section to add
"resources": [
{
"type": "extensions",
"name": "Microsoft.Insights.VMDiagnosticsSettings",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Diagnostics",
"type": "IaaSDiagnostics",
"typeHandlerVersion": "1.12",
"autoUpgradeMinorVersion": true,
"settings": {
"WadCfg": {
"DiagnosticMonitorConfiguration": {
"overallQuotaInMB": 4096,
"DiagnosticInfrastructureLogs": {
"scheduledTransferLogLevelFilter": "Error"
},
"Directories": {
"scheduledTransferPeriod": "PT1M",
"IISLogs": {
"containerName": "wad-iis-logfiles"
},
"FailedRequestLogs": {
"containerName": "wad-failedrequestlogs"
}
},
"PerformanceCounters": {
"scheduledTransferPeriod": "PT1M",
"sinks": "AzMonSink",
"PerformanceCounterConfiguration": [
{
"counterSpecifier": "\\Memory\\Available Bytes",
"sampleRate": "PT15S"
},
{
"counterSpecifier": "\\Memory\\% Committed Bytes In Use",
"sampleRate": "PT15S"
},
{
"counterSpecifier": "\\Memory\\Committed Bytes",
"sampleRate": "PT15S"
}
]
},
"WindowsEventLog": {
"scheduledTransferPeriod": "PT1M",
"DataSource": [
{
"name": "Application!*"
}
]
},
"Logs": {
"scheduledTransferPeriod": "PT1M",
"scheduledTransferLogLevelFilter": "Error"
}
},
"SinksConfig": {
"Sink": [
{
"name" : "AzMonSink",
"AzureMonitor" : {}
}
]
}
},
"StorageAccount": "[variables('storageAccountName')]"
},
"protectedSettings": {
"storageAccountName": "[variables('storageAccountName')]",
"storageAccountKey": "[listKeys(variables('accountid'),'2015-06-15').key1]",
"storageAccountEndPoint": "https://core.windows.net/"
}
}
}
]
//End of section to add
Save and close both files.
Note
You must be running the Azure Diagnostics extension version 1.5 or higher AND have the autoUpgradeMinorVersion: property set to ‘true’ in your Resource Manager template. Azure then loads the proper extension when it starts the VM. If you don't have these settings in your template, change them and redeploy the template.
To deploy the Resource Manager template, we leverage Azure PowerShell.
-
Launch PowerShell.
-
Log in to Azure using
Login-AzureRmAccount
. -
Get your list of subscriptions by using
Get-AzureRmSubscription
. -
Set the subscription that you're using to create/update the virtual machine in:
Select-AzureRmSubscription -SubscriptionName "<Name of the subscription>"
-
To create a new resource group for the VM that's being deployed, run the following command:
New-AzureRmResourceGroup -Name "<Name of Resource Group>" -Location "<Azure Region>"
[!NOTE] Remember to use an Azure region that is enabled for custom metrics.
-
Run the following commands to deploy the VM using the Resource Manager template.
[!NOTE] If you wish to update an existing VM, simply add -Mode Incremental to the end of the following command.
New-AzureRmResourceGroupDeployment -Name "<NameThisDeployment>" -ResourceGroupName "<Name of the Resource Group>" -TemplateFile "<File path of your Resource Manager template>" -TemplateParameterFile "<File path of your parameters file>"
-
After your deployment succeeds, the VM should be in the Azure portal, emitting metrics to Azure Monitor.
[!NOTE] You might run into errors around the selected vmSkuSize. If this happens, go back to your azuredeploy.json file, and update the default value of the vmSkuSize parameter. In this case, we recommend trying "Standard_DS1_v2").
-
Log in to the Azure portal.
-
On the left menu, select Monitor.
-
On the Monitor page, select Metrics.
-
Change the aggregation period to Last 30 minutes.
-
In the resource drop-down menu, select the VM that you created. If you didn't change the name in the template, it should be SimpleWinVM2.
-
In the namespaces drop-down menu, select azure.vm.windows.guest
-
In the metrics drop down menu, select Memory%Committed Bytes in Use.
- Learn more about custom metrics.