I need to get some metrics for Azure an app service . Values are the CPU (in %) and Memory consumed ( in %). I want to report if for example the CPU is high for a certain period of time , in order to give an indication that the app service is consuming high memory or resources and then send an email .
I am currently using
Get-AzMetricDefinition -ResourceId
"/subscriptions/<subscriptionid>/resourceGroups/Default-Web-
EastUS/providers/microsoft.web/sites/website2" -DetailedOutput -MetricName
"BytesSent,CpuTime"
But from this how can i get the % CPU and % Memory. Or is there a different Powershell command ?
To get the CPU usage for an Azure app service using PowerShell:
There is an Azure PowerShell command called
Get-AZMetricto get all the metrics data from a particular resource (Eg: App Service). However,CPU %is not a supported argument forGet-AZMetric, if you copy theresourceIDof the Web App properities as it is a cloud service ID.We can achieve it for overall
AppServicePlanasCPU %supports here.If the app services hosted in premium, standard and basic plans,
CPU%will comes because of scaling out feature whereasCPU_Timeis helpful when hosted in free or the shared app service plans.After investigating, I've found a way to achieve it with the help of AppServicePlan by taking resourceID as shown:
Metrics for CPU Percentage:
Metrics for Memory Percentage:
Note:
"Diagnose and solve problems"if needed.