KQL查询如何按集群分组统计Azure AKS集群的总节点数量
修改后的完整KQL语句
resources | join kind=leftouter (ResourceContainers | where type=='microsoft.resources/subscriptions' | project SubscriptionName=name, subscriptionId) on subscriptionId | where type =='microsoft.containerservice/managedclusters' | extend properties.agentPoolProfiles | project id, SubscriptionName,location, name,pool = (properties.agentPoolProfiles) | mv-expand pool | project id, SubscriptionName,cluster = name, size = pool.vmSize, nodes = pool.['count'] // 新增以下分组求和语句即可得到目标结果 | summarize nodes = sum(nodes) by cluster
修改说明
你现有查询返回多行重复集群记录的原因是:mv-expand操作会把每个集群的多个节点池拆分为独立行。新增的summarize语句会按cluster字段分组,对同一集群所有节点池的节点数求和,最终输出的列名和结构完全符合你要求的格式。
如果需要同时保留订阅名称、集群ID等其他原有字段,只需把对应字段添加到by参数后即可,示例:
| summarize nodes = sum(nodes) by cluster, SubscriptionName, id
内容的提问来源于stack exchange,提问作者nailuenlue
相关产品推荐
相关产品推荐

