我想要90天的时间粒度为1天,即24小时的虚拟机Azure指标。当我尝试,它与错误的请求失败。
Get-AzureRMMetric -ResourceId $vm[0].Id -TimeGrain 24:00:00 -MetricName "Percentage CPU" -StartTime (Get-Date).adddays(-90) -EndTime (Get-Date)
错误如下
Get-AzureRMMetric : 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()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Monitor.MetricsOperationsExtensions.<ListAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Commands.Insights.Metrics.GetAzureRmMetricCommand.ProcessRecordInternal()
at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet(), Code: Null, Status code:Null, Reason phrase: Null
At line:1 char:9
+ $metric=Get-AzureRMMetric -ResourceId $vm[0].Id -TimeGrain 24:00:00 - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureRmMetric], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Metrics.GetAzureRmMetricCommand
3条答案
按热度按时间fsi0uk1n1#
powershell -Timegrain的语法为
因此,要在请求中获得1天的时间跨度,您可以编写
希望这能帮上忙问候你约翰。
shyt4zoc2#
当它显示BadRequest时,很可能你传递了一些错误的参数。我看到,你调用Id来传递resourceId,我怀疑可能有问题。
请查看以下详细信息,这些信息将为您提供度量标准:
mwg9r5ms3#
这对我来说绝对有效:
在PowerShell 7下测试:
如果您想在某一天(比如昨天)使用: