Search code examples
azureazure-powershellmetricsazure-alerts

Unable to create Alert for podReadyPercentage metrics


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

[![enter image description here][1]][1]

So not sure what else I am missing here. Any help anyone?

tried to google MS docs


Solution

  • podReadyPercentage metric disabled and no way to create a alert from portal, refer this Ms Doc

    enter image description here

    Alternatively, 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

        KubePodInventory
        | summarize TotalPods = count(), ReadyPods = countif(ContainerID != "None" and PodStatus == "Running") by ClusterName
        | extend PodReadyPercentage = toreal(ReadyPods) / toreal(TotalPods) * 100
    

    Pod Ready Percentage

    enter image description here

    1. Create an alert by clicking New Alert Rule and providing the required details to receive an alert based on the Pod Ready Percentage..

    enter image description here

    1. Create an action group or select an existing one to send an email.

    enter image description here

    You will receive an alert whenever the Pod percentage falls below 50%.