Customizing, Exporting and Importing Azure VM Diagnostic Settings


Azure VM Diagnostics on Windows VMs can track more than just the basic performance counters. Through the Azure portal UI as in the image below you can add performance counters that are available to the operating system. Inside of windows run "Typeperf -q > counters.txt" at a command prompt to get a txt file of all the available counter names, then add the seem as seen here:
Performance Counters

Once you have added all of the custom performance counters you want, you can use the powershell below to export the configuration to a JSON file, then apply to existing or new VMs. The PowerShell below assumes an existing virtual machine with no azure diagnostics extension installed. It would be fairly simple to add a check to see if extensions are installed and remove/re-add with the imported config as well as use powershell to update the json file for new diagnostic storage account locations and resourceIDs.


Login-AzureRmAccount
#source resource group and virtual machine to take the diagnostic settings from.
$rg = 'resourcegroup1
$vm = 'vm1'
$diag = (Get-AzureRmVMDiagnosticsExtension -ResourceGroupName $rg -VMName $vm).publicsettings
$path = 'c:\users\joknight\diag.json'
$diag | out-file $path
$targetVM='targetvm'
$targetRG='targetrg'
#you may want to edit the diagnostics storage account in the diag.json file
#be sure to edit the resourceID in the diag.json file to match the target VM
Set-AzureRmVMDiagnosticsExtension -ResourceGroupName $targetrg -VMName $targetvm -DiagnosticsConfigurationPath $path


Comments (0)

Skip to main content