You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

获取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&timespan=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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 06:54:03