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

能否编写Kusto查询获取Azure容器应用的内存/CPU使用率占比?

获取Azure Container App内存/CPU使用率占限制的百分比的Kusto查询

方法1:结合AppPerformanceCounters与ContainerAppRevisions计算

AppPerformanceCounters仅提供进程级使用数据,缺少资源限制值,需关联存储修订版配置的ContainerAppRevisions表来计算占比。

CPU使用率占限制百分比查询

AppPerformanceCounters
| where TimeGenerated > ago(1h)
| where ContainerAppName == "你的容器应用名称"
| where CounterName == "% Processor Time"
| join kind=inner (
    ContainerAppRevisions
    | where ContainerAppName == "你的容器应用名称"
    // 若Cpu字段带单位(如"0.5 vCPU"),提取数值
    | extend CpuLimit = toreal(split(Cpu, " ")[0])
    | project ContainerAppName, RevisionName, CpuLimit
) on ContainerAppName, RevisionName
// 计算占比:进程CPU使用率 / (限制vCPU数 * 100) * 100
| extend CpuUsagePercentOfLimit = round(CounterValue / (CpuLimit * 100) * 100, 2)
| project TimeGenerated, ContainerAppName, RevisionName, 进程CPU使用率=CounterValue, CPU限制_vCPU=CpuLimit, CPU使用率占限制百分比=CpuUsagePercentOfLimit
| sort by TimeGenerated desc

内存使用率占限制百分比查询

AppPerformanceCounters
| where TimeGenerated > ago(1h)
| where ContainerAppName == "你的容器应用名称"
| where CounterName == "Private Bytes"
| join kind=inner (
    ContainerAppRevisions
    | where ContainerAppName == "你的容器应用名称"
    // 若Memory字段带单位(如"1 Gi"),提取数值并转换为字节
    | extend MemoryGi = toreal(split(Memory, " ")[0])
    | extend MemoryLimitBytes = MemoryGi * 1024 * 1024 * 1024
    | project ContainerAppName, RevisionName, MemoryLimitBytes
) on ContainerAppName, RevisionName
// 计算占比:私有字节数 / 内存限制字节数 * 100
| extend MemoryUsagePercentOfLimit = round((CounterValue / MemoryLimitBytes) * 100, 2)
| project TimeGenerated, ContainerAppName, RevisionName, 私有字节数=CounterValue, 内存限制_字节=MemoryLimitBytes, 内存使用率占限制百分比=MemoryUsagePercentOfLimit
| sort by TimeGenerated desc

方法2:使用AzureMetrics直接获取预计算的占比

Azure平台已在AzureMetrics表中提供了直接基于资源限制计算的使用率百分比指标,无需手动关联计算:

AzureMetrics
| where TimeGenerated > ago(1h)
| where ResourceProvider == "Microsoft.App/containerApps"
| where MetricName in ("ContainerAppCPUUsagePercentage", "ContainerAppMemoryUsagePercentage")
| where Resource == "你的容器应用名称"
| project TimeGenerated, 容器应用名称=Resource, 指标名称=MetricName, 平均使用率百分比=Average, 最小使用率百分比=Minimum, 最大使用率百分比=Maximum
| sort by TimeGenerated desc

内容的提问来源于stack exchange,提问作者Jens Roderus

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 09:46:06