Get-AzMetric in PowerShell to get "Request count" metrics from Azure Front Door and CDN profiles

New Contributor

I have a fairly simple requirement. I am trying to use the Get-AzMetric cmdlet for PowerShell to extract "Request Count" with aggregation "SUM" metrics for an Azure Classic Cloud service. (This is same information shows in the portal under resource group --> Front Door and CDN profiles --> Monitoring -> Metrics.)

My script as below:

Get-AzMetric -ResourceId "/subscriptions/******" -MetricName "Request Count" -TimeGrain 00:01:00 -DetailedOutput

Error Message:-

Get-AzMetric : Exception type: ErrorResponseException, Message: Microsoft.Azure.Management.Monitor.Models.ErrorResponseException: Operation returned an invalid status
code 'BadRequest'
at Microsoft.Azure.Management.Monitor.MetricsOperations.<ListWithHttpMessagesAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

 

 

Even I have tried to get the result with below frontdoor cdn profile but getting an access error (With the same reader role I am able to get result via GUI)

Get-AzFrontDoorCdnProfileResourceUsage -ResourceGroupName ***** -ProfileName ***--

Error:- Get-AzFrontDoorCdnProfileResourceUsage : The client '@.net' with object id '*******' does not have authorization to perform action 'Microsoft.Cdn/profiles/usages/action' over scope

Please help me to resolve this script error to get the output of metrics (Request count) with Aggregation SUM.

My scripts as below:

1. Get-AzMetric -ResourceId "/subscriptions/******" -MetricName "Request Count" -TimeGrain 00:01:00 -DetailedOutput

2. Get-AzFrontDoorCdnProfileResourceUsage -ResourceGroupName ***** -ProfileName ***--

 

When I execute second script it gives me access error.

 

Get-AzFrontDoorCdnProfileResourceUsage : The client 'xyz@**.net' with object id '******' does not have authorization to perform action 'Microsoft.Cdn/profiles/usages/action' over scope '/subscriptions/*****/resourceGroups/*****/providers/Microsoft.Cdn/profiles/*****' or the scope is invalid.

0 Replies