azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Is there any other way to retrieve all the data (aggregation) when using Get-Azmetric command in powershell?

Open maeganda11 opened this issue 4 years ago • 9 comments

Description

Hi, does anyone able to retrieve all the data when using Get-AzMetric command in powershell? By default, it will only shows the Average but not the Minimum ,Maximum, Total and Count .. unless specify the Aggregation type on the command.

Would like to ask if it is possible to show all data in one run (Average, Maximum, Minimum, Total and Count). Thank you.

Here is the command I use. $CPU = Get-AzMetric -ResourceId $VMname.Id -TimeGrain 00:15:00 -StartTime $st -EndTime $et -MetricName "Percentage CPU" -DetailedOutput $CPU.Data

image

Script or Debug output

No response

Environment data

No response

Module versions

No response

Error output

No response

maeganda11 avatar Nov 17 '22 10:11 maeganda11

Thank you for your feedback. This has been routed to the support team for assistance.

ghost avatar Nov 17 '22 12:11 ghost

Hi @Maeganda11 , for VM resource, aggregation type only supports average. Please reference https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftcomputevirtualmachines

dingmeng-xue avatar Nov 17 '22 12:11 dingmeng-xue

Hi @maeganda11. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost avatar Nov 17 '22 12:11 ghost

From this link, every metric supports only one Aggregation Type. But it's not correct. We can specify Aggregation type to get Maximum, Maximum and other aggregation type data. And if you call Get-AzMetricDefinition, you can get which aggregation type is supported for a specified resource. here is an example: PrimaryAggregationType : Average SupportedAggregationTypes : {Average, Maximum, Minimum} So the link you provided only means the primary aggregation type. I also want to know if there is a way to get all supported aggregation type data in one call.

hanhsia avatar Nov 19 '22 09:11 hanhsia

Hi @hanhsia , Azure PowerShell's implementation bases on public API and doc. For further clarification, please wait support team or service team's answer.

dingmeng-xue avatar Nov 20 '22 14:11 dingmeng-xue

@maeganda11 Apologies for the late reply. Thanks for reaching out to us and reporting this issue. We are looking into this issue and we will provide an update.

navba-MSFT avatar Dec 01 '22 03:12 navba-MSFT

@maeganda11 @hanhsia The Azure Monitor List Metrics REST API expects the aggregation query string parameter.

aggregation query   string The list of aggregation types (comma separated) to retrieve.

When I invoked the below REST API directly as shown below:

https://management.azure.com//subscriptions/XXXXXXXX/resourceGroups/Allrg/providers/Microsoft.Compute/virtualMachines/MYVMNAME/providers/Microsoft.Insights/metrics?api-version=2018-01-01&aggregation=minimum%2Caverage%2Cmaximum

I got the desired output see below:

image

Could you try to invoke the above REST API from powershell and check if that helps. ? Also refer this sample PS script in this thread.

navba-MSFT avatar Dec 01 '22 09:12 navba-MSFT

Hi @maeganda11. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

ghost avatar Dec 01 '22 09:12 ghost

Hi @maeganda11, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.

ghost avatar Dec 08 '22 12:12 ghost