I am trying to create a MetricAlert using the following script
Set-AzContext -Subscription "f0bXXXXXXX"
$action = Get-AzActionGroup -ResourceGroupName gze-actgrp-pd-rgp-001 -Name UWDevOps_PD
$actionID = New-AzActionGroup -ActionGroupId $action.id
#Get-AzMetricDefinition -ResourceId "/subscriptions/9ca9XXXXX/resourcegroups/gze-pdi203-pd1-rgp-001/providers/Microsoft.ContainerService/managedClusters/gze-pdi203-pd1-aks-isostr-001"
#set alert dim to pick the right options
$dim = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "Kubernetes namespace" -ValuesToInclude "dv1"
$severity = 1
$RGObject = "gze-npi203-np1-rgp-001"
$ResourceId = "/subscriptions/9caXXXXXXX/resourcegroups/gze-npi203-np1-rgp-001/providers/Microsoft.ContainerService/managedClusters/gze-npi203-np1-aks-isostr-001"
#set alert criteria and counter % Processor Time
$criteria = New-AzMetricAlertRuleV2Criteria -MetricName "podReadyPercentage" -DimensionSelection $dim
-TimeAggregation average -Operator LessThan
-Threshold 50
Set-AzContext -Subscription "921XXXX" # subID of the GZ-NP-IT-203-AKSISDUWSYS
Add-AzMetricAlertRuleV2 -Name "UWS-AKS203-ISOSTR-DV1-[Sev0-Critical]-Pods-Ready-Percentage less than 50-V2-CT" -ResourceGroupName $RGObject
-WindowSize 01:00:00 -Frequency 01:00:00
-TargetResourceId $ResourceId -Condition $criteria
-ActionGroup $actionID `
-Severity $severity
Error "Couldn’t find a metric named podReadyPercentage."
Add-AzMetricAlertRuleV2 : Exception type: ErrorResponseException, Message: Couldn’t find a metric named podReadyPercentage. Make sure the name is correct. Activity ID:
192c5e83-2b8a-4cd3-861b-da8dd2da8c1f., Code: BadRequest, Status code:BadRequest, Reason phrase: BadRequest
At line:1 char:1
Add-AzMetricAlertRuleV2 -Name "UWS-AKS203-ISOSTR-DV1-[Sev0-Critical]- …
- CategoryInfo : CloseError: (:) [Add-AzMetricAlertRuleV2], PSInvalidOperationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Alerts.AddAzureRmMetricAlertRuleV2Command
=========================
But as per MS doc that is the name listed https://learn.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-custom-metrics?tabs=portal
So not sure what else I am missing here. Any help anyone?
tried to google MS docs
2
Answers
I am unable to create alerts for any of the preview ones.. I am using Az.Monitor ver 3.1.0 and Az ver 10.0.1, if that may help..
I needed Az.Monitor ver 3.1.0 for New-AzActionGroup cmdlet to work.
podReadyPercentage
metric disabled and no way to create a alert from portal, refer this Ms DocAlternatively, you can create an alert for the ‘Pod ready percentage‘ using
Log Analytics
.1.Go to your cluster > Logs > and run below KQL Query
KQL Query
Pod Ready Percentage
New Alert Rule
and providing the required details to receive an alert based on thePod Ready Percentage
..action group
or select an existing one to send an email.You will receive an alert whenever the
Pod percentage
falls below 50%.