Closed SriHarsha001 closed 6 years ago
@gucalder Can you take a look?
Changing the metric name to "\Processor(_Total)\% Processor Time" worked. We need to use CounterSpecifier instead of display name in PS command.
Add-AzureRMMetricAlertRule -Name "CpuRule" -Location "" -ResourceGroup "" -Operator GreaterThan -Threshold 2 -WindowSize 00:05:00 -MetricName "CPU utilization" -Description "" -TimeAggregationOperator Total
Add-AzureRMMetricAlertRule -Name "CpuRule" -Location "" -ResourceGroup "" -Operator GreaterThan -Threshold 2 -WindowSize 00:05:00 -MetricName "\Processor(_Total)\% Processor Time" -Description "" -TimeAggregationOperator Total
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT15S" unit="Percent">
<annotation displayName="CPU utilization" locale="en-us"/>
</PerformanceCounterConfiguration>
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Privileged Time" sampleRate="PT15S" unit="Percent">
<annotation displayName="CPU privileged time" locale="en-us"/>
</PerformanceCounterConfiguration>
Cmdlet -
Add-AzureRmMetricAlertRule
PowerShell Version -
5.1.16299.98
Module Version -
10.0.16299.98
Description -
After enabling guest-level metrics/diagnostics on Virtual Machines, we are unable to create metric rules using the new guest metrics with the PowerShell SDK.
Even after updating version of the 'AzureRM.Insights' module to version 4.0.0 (the most recent), we are getting the following error message:
'Add-AzureRmMetricAlertRule : Exception type: ErrorResponseException, Message: The metric 'CPU utilization' is not supported for resource '/subscriptions//resourceGroups/testcp1-core-resource-group/ providers/Microsoft.Compute/virtualMachines/testcp1-dc02'. If this is a guest agent metric, please make sure that you have successfully configured the diagnostics extension and that you are able to see the metric in the Azure Portal., Code: UnsupportedMetric, Status code:BadRequest, Reason phrase: Bad Request At line:1 char:5
We can see that 'CPU utilization' and other guest agent metrics do in fact appear within the Azure RM portal.
Script/Steps for Reproduction
Enabling guest-level diagnostics for the VM - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/ps-extensions-diagnostics?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json
PS cmdlet to confiure alerts - https://docs.microsoft.com/en-us/powershell/module/azurerm.insights/add-azurermmetricalertrule?view=azurermps-5.1.1 Add-AzureRMMetricAlertRule -Name "CpuRule" -Location "" -ResourceGroup "" -Operator GreaterThan -Threshold 2 -WindowSize 00:05:00 -MetricName "CPU utilization" -Description "" -TimeAggregationOperator Total
Debug Output
DEBUG: ============================ HTTP REQUEST ============================ HTTP Method: PUT
Absolute Uri: https://management.azure.com/subscriptions//resourcegroups//providers/m
icrosoft.insights/alertrules/CpuPercentageRule?api-version=2016-03-01
Headers: x-ms-client-request-id : 41de95f0-0e97-4a73-b96c-c3affe5d2de9 accept-language : en-US
Body: { "properties": { "name": "CpuPercentageRule", "description": "Testing", "isEnabled": true, "condition": { "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition", "operator": "GreaterThan", "threshold": 2.0, "windowSize": "PT5M", "timeAggregation": "Total", "dataSource": { "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource", "metricName": "CPU utilization", "resourceUri": "/subscriptions//resourcegroups//providers/Microsoft.Compute/virtualMac
hines/GuestMetrics"
}
}
},
"location": "Azure DC",
"tags": {
"$type":
"Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary,Microsoft.WindowsAzure.Management.Common.Stor
age",
"hidden-link:/subscriptions//resourcegroups//providers/Microsoft.Comput
e/virtualMachines/": "Resource"
}
}
DEBUG: ============================ HTTP RESPONSE ============================ Status Code:BadRequest
Headers: Pragma : no-cache Strict-Transport-Security : max-age=31536000; includeSubDomains x-ms-request-id : 00000000-0000-0000-0000-000000000000 x-ms-ratelimit-remaining-subscription-writes: 1199 x-ms-correlation-request-id : 58653157-5e8c-48c0-a51d-f75b39e87b6f x-ms-routing-request-id : WESTUS2:20171227T192012Z:58653157-5e8c-48c0-a51d-f75b39e87b6f Cache-Control : no-cache Date : Wed, 27 Dec 2017 19:20:12 GMT Server : Microsoft-IIS/8.5
Body: { "code": "UnsupportedMetric", "message": "The metric 'CPU utilization' is not supported for resource '/subscriptions//resourcegroups//providers/Microsoft.Compute/virtualMac
hines/VMName'. If this is a guest agent metric, please make sure that you have successfully configured the
diagnostics extension and that you are able to see the metric in the Azure Portal."
}
Add-AzureRMMetricAlertRule : Exception type: ErrorResponseException, Message: The metric 'CPU utilization' is not supported for resource '/subscriptions//resourcegroups//providers/Micro
soft.Compute/virtualMachines/'. If this is a guest agent metric, please make sure that you have
successfully configured the diagnostics extension and that you are able to see the metric in the Azure Portal., Code:
UnsupportedMetric, Status code:BadRequest, Reason phrase: Bad Request
At line:1 char:1
DEBUG: AzureQoSEvent: CommandName - Add-AzureRmMetricAlertRule; IsSuccess - False; Duration - 00:00:17.2502645; Exception - System.Management.Automation.PSInvalidOperationException: Exception type: ErrorResponseException, Message: The metric 'CPU utilization' is not supported for resource '/subscriptions//resourcegroups//providers/Microsoft.Compute/virtualMac
hines/'. If this is a guest agent metric, please make sure that you have successfully configured the
diagnostics extension and that you are able to see the metric in the Azure Portal., Code: UnsupportedMetric, Status
code:BadRequest, Reason phrase: Bad Request --->
Microsoft.Azure.Management.Monitor.Management.Models.ErrorResponseException: Operation returned an invalid status code
'BadRequest'
at
Microsoft.Azure.Management.Monitor.Management.AlertRulesOperations.d__5.MoveNext()
--- End of inner exception stack trace ---
at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 11:20:13 AM - AddAzureRmMetricAlertRuleCommand end processing.
DEBUG: 11:20:13 AM - AddAzureRmMetricAlertRuleCommand end processing.