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

Kusto查询VM健康仪表盘场景下条件过滤统计问题求助

Kusto VM健康状态分类统计解决方案

你需要用extend算子新增分类标识列替代where过滤逻辑,where会剔除不符合条件的数据,而你需要保留所有符合基础过滤规则的VM进行归类统计,完整实现如下:

VM
| where VMName has "XYZ" 
| where VMName !has "XYZ123"
| where VMName has_any ("s","t","u","v")
// 新增分类列,按规则给VM打标签
| extend StatusCategory = case(
    mode == "online" and enabled == true, "enabled",
    mode == "offline" and enabled == true, "disabled",
    "other"
)
// 不需要统计其他类VM时可以打开下方注释
// | where StatusCategory != "other"
// 统计各分类数量、总数、enabled占比
| summarize 
    enabled_count = countif(StatusCategory == "enabled"),
    disabled_count = countif(StatusCategory == "disabled")
| extend total_count = enabled_count + disabled_count
| extend enabled_rate = round(todouble(enabled_count) / total_count * 100, 2) // 输出保留2位小数的百分比值

核心逻辑说明

  • case()是Kusto的多条件判断函数,支持按自定义规则匹配返回对应分类值
  • countif()可以直接按条件统计对应分类的数量,无需额外分组操作
  • 计算占比时通过todouble()先把整数转为浮点数,避免整数除法得到0的错误结果,round()的第二个参数可以按需调整百分比保留的小数位数

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 04:27:02