azure - 如何在azure powershell中获取1天时间粒度的指标数据?

标签 azure powershell

我想要虚拟机的 90 天 Azure 指标,时间粒度为 1 天,即 24 小时。 我正在尝试它因错误请求错误而失败。

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

最佳答案

powershell -Timegrain 的语法是

d.HH:MM:ss

因此,要在请求中获得 1 天的时间跨度,您可以编写

-TimeGrain 1.00:00:00

希望这有帮助。 问候,约翰。

关于azure - 如何在azure powershell中获取1天时间粒度的指标数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57922767/

相关文章:

windows - 如何从 Get-ChildItem 获取所有可执行文件的路径

用于监视日志并将进度输出到另一个日志的 PowerShell 脚本

azure - 添加新集合时对 Azure Cosmos DB 模拟器的高要求

azure - Terraform Azure Key Vault - 超出了上下文截止日期

Azure:结合 Web 和辅助角色:应用程序池回收

azure - 使用 MQTT 创建从 Eclipse-ditto 到 Azure IoT 中心的连接

perl - Wantarray等效?

azure - 是否可以在 Azure 门户之外访问 Azure 安全中心建议?

windows - 从 PowerShell 调用 Windows 运行时类 - window 8 Lockscreen Switcher

.net - winforms关闭事件的不同原因