获取App Service Plan资源消耗详情的Azure API查询咨询
Azure App Service Plan 消耗监控查询API指引
首选方案:Azure Monitor 指标API
这是获取App Service Plan运行时监控数据的官方标准接口,可直接返回你需要的所有核心指标数据,支持自定义时间范围、统计维度和聚合方式。
支持的核心指标
- CPU使用率:对应指标标识为
CpuPercentage,支持按实例维度拆分统计 - 内存使用率:对应指标标识为
MemoryPercentage - 流入流量:对应指标标识为
BytesReceived,统计单位为字节 - 流出流量:对应指标标识为
BytesSent,统计单位为字节
基础请求格式
GET https://management.azure.com/subscriptions/{替换为你的订阅ID}/resourceGroups/{替换为你的资源组名称}/providers/Microsoft.Web/serverfarms/{替换为你的App Service Plan名称}/providers/microsoft.insights/metrics?api-version=2018-01-01&metricnames=CpuPercentage,MemoryPercentage,BytesReceived,BytesSent&aggregation=Average,Total×pan=2024-01-01T00:00:00Z/2024-01-02T00:00:00Z
参数说明:
metricnames:可按需传入你需要查询的指标名称,多个用英文逗号分隔aggregation:指定统计方式,可选值包括Average(平均值)、Total(总和)、Maximum(峰值)、Minimum(谷值)timespan:指定查询的时间范围,格式为开始时间ISO格式/结束时间ISO格式,最大支持查询90天内的数据
接口调用要求
- 提前在Azure AD中注册服务主体,获取
client_id、client_secret、tenant_id用于获取授权凭证 - 给该服务主体分配目标App Service Plan的监控读取者及以上权限
- 调用接口前先获取OAuth2.0访问令牌,将令牌放在请求头的
Authorization字段中,格式为Bearer {你的访问令牌}
补充可选方案
如果你需要同时查询App Service Plan的基础配置和资源配额消耗情况,可使用Azure Resource Graph API,配套查询语句示例:
Resources | where type =~ 'Microsoft.Web/serverfarms' | where name == '{替换为你的App Service Plan名称}' | project name, resourceGroup, sku.name, sku.capacity, properties.currentWorkerCount, properties.maximumElasticWorkerCount
该接口可以一次性返回计划的实例数、弹性扩缩容配置、当前配额使用情况等信息。
内容的提问来源于stack exchange,提问作者samssagar
相关产品推荐
相关产品推荐

