通过 powershell 或 azure cli 获取 Azure VM 概览/监控数据

通过 powershell 或 azure cli 获取 Azure VM 概览/监控数据

当我们登录 Azure 门户并查看任何资源(例如 VM)时,我们将在每个资源的“概览”部分看到一些监控数据,这些数据向我们显示了 30 天的图表。(CPU 平均值、网络输入/输出等)

我的要求是不通过门户或 CLI 对 Azure 资源进行任何更改。但我更希望找到一个 powershell / azure cli 命令,它将把所有这些数据从 Azure 拉到我的本地机器进行一些分析。

我正在寻找 VM、Web 应用程序和 Azure SQL。

谢谢

答案1

你说得对,我们可以使用 CLI 2.0 来获取指标数据:

az monitor metrics list --resource /subscriptions/xxxxxxx/resourceGroups/xxxxx/providers/Micros‌​oft.Compute/virtualM‌​achines/xxxx --metric-names "Percentage CPU" --time-grain "PT1M" >> PercentageCpuData.txt

我们还可以使用 Azure PowerShell 命令Get-AzureRmMetricDefinition来获取指标。

以下是 Azure VM 的指标:

PS D:\testdata> (Get-AzureRmMetricDefinition -ResourceId $id).name

Value                     LocalizedValue
-----                     --------------
Percentage CPU            Percentage CPU
Network In                Network In
Network Out               Network Out
Disk Read Bytes           Disk Read Bytes
Disk Write Bytes          Disk Write Bytes
Disk Read Operations/Sec  Disk Read Operations/Sec
Disk Write Operations/Sec Disk Write Operations/Sec
CPU Credits Remaining     CPU Credits Remaining
CPU Credits Consumed      CPU Credits Consumed

然后我们可以使用该值来获取其他指标:

Get-AzureRmMetric -ResourceId $id -TimeGrain 00:01:00 -DetailedOutput -MetricNames "Network in"

这里类似案件关于你,请参考。

顺便说一下,关于 Azure Host 指标和 Guest 指标的区别,请参考这里关联

相关内容