如何使用 REST API 或通过 Java SDK 监控 Azure 经典虚拟机?

How to monitor Azure Classic VM using REST API or via Java SDK?

嗨,我想使用 REST API/Java SDK 监视 Azure Classic VM,当我尝试使用 REST API 和以下 URL(下面的 url 有效对于 Azure 虚拟机)

https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/Preprod2-Resource-Group/providers/Microsoft.ClassicCompute/virtualMachines/cloudops-testvm1/providers/microsoft.insights/metrics?api-version=2016-09-01

我收到以下错误

{ "code": "NotFound", "message": "Resource provider not found: [Microsoft.ClassicCompute]" }

请建议我是否可以通过 REST API 或者如果有 SDK 请建议我。

我的要求是我想监控经典 VM 并收集网络输入、网络输出、百分比 CPU、磁盘读取 Operations/Sec、磁盘写入 Operations/Sec、磁盘写入字节和磁盘每 5 分钟读取一个字节

根据指标 API,这不是受支持的资源类型。支持的类型和指标在此处:Supported metrics with Azure Monitor。您可以查看此 link,目前不支持经典 VM。

根据您的描述,您可以使用Metric Definitions API。它适用于经典 VM。

https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/<resourceGroups/>/providers/Microsoft.ClassicCompute/virtualMachines/<Virutal name>/providers/microsoft.insights/metricdefinitions?api-version=2015-07-01

指标信息存储在 Azure 存储帐户中,您也可以调用 Storage API 来获取 VM 指标。更多信息请参考这个link:Storage Analytics.