No Extensions! Getting Basic Azure VM Metric Data

If you need to grab some basic performance metrics on an Azure Virtual Machine that doesn't have either the OMS or Azure Monitor extensions, it can still be done with the metrics here: Basic Metrics

You can then use the GUI to create alerts (which this blog won't cover) or if you have 100's of VMs to set this on, use PowerShell! In this use case, the virtual machines that are using less than 25% CPU need to be discovered so they can be sized down. This alert could call a webhook (which could call an Azure Automation, which is covered in previous blog posts), but for this example, it's just email.

The script checks to see if the VM is running and if it is, sets an alert to send an email if the CPU is under 25% for 1 day. The script can be found here

The version as of this writing is below:
Login-AzureRmAccount Select-AzureRmSubscription -SubscriptionName 'subscriptionName' $vm = Get-AzureRMVm $actionEmail = New-AzureRmAlertRuleEmail -CustomEmail none@none.com foreach ($v in $vm) {$status = Get-AzureRmVM -ResourceGroupName $v.ResourceGroupName -Name $v.Name -Status if ($status.Statuses[1].DisplayStatus -contains 'VM Running'){ Add-AzureRmMetricAlertRule -Name vmcpu_lt_25 -Location $v.location -ResourceGroup $v.resourcegroupname -TargetResourceId $v.Id -MetricName "Percentage CPU" -Operator LessThan -Threshold 25 -WindowSize 01:00:00 -TimeAggregationOperator Average -Actions $actionEmail -Description "alert on CPU < 25%" } }