Microsoft Azure – 使用 KQL 为孤立资源创建饼图
工作簿允许将监控数据显示为图表。它支持日志和指标数据源的图表。孤立资源是在删除关联 VM 时未处理的那些资源。若要了解有关使用 KQL 查询 Azure 资源的更多信息,请查看本文。
在本文中,我们将研究通过工作簿使用 KQL 表示孤立资源的过程:
实现:
按照以下查询来实施问题陈述:
Note: You can use Workbooks to Save the Graph Queries and You can Pin to Dashboard for Analysis.
1. 按订阅类别获取 Azure 孤立磁盘计数:
KQL Azure 资源图查询:
Resources
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState)
| where diskState == 'Unattached' or managedBy == ""
| extend SubscriptionName=case(subscriptionId =~ 'Add Subscripton 1 Id here ', 'Add Subscripton 1 Name Here',
subscriptionId =~ 'Add Subscripton 2 Id here ', 'Add Subscripton 2 Name Here'
subscriptionId =~ 'Add Subscripton 3 Id here ', 'Add Subscripton 3 Name Here'
,subscriptionId) // You can in similar way to add more
| summarize count() by SubscriptionName
输出:
2. 按订阅类别获取 Azure 孤立 NIC 的计数:
KQL Azure 资源图查询:
Resources
| where type has "microsoft.network/networkinterfaces"
| where properties !has 'virtualmachine'
| extend SubscriptionName=case(subscriptionId =~ 'Add Subscripton 1 Id here ', 'Add Subscripton 1 Name Here',
subscriptionId =~ 'Add Subscripton 2 Id here ', 'Add Subscripton 2 Name Here'
subscriptionId =~ 'Add Subscripton 3 Id here ', 'Add Subscripton 3 Name Here'
,subscriptionId) // You can in similar way to add more
| summarize count() by SubscriptionName
输出:
3. 按订阅类别获取 Azure 孤立 NSG 的计数:
KQL Azure 资源图查询:
Resources
| where type =~ 'microsoft.network/networksecuritygroups'
and isnull(properties.networkInterfaces)
and isnull(properties.subnets)
| extend SubscriptionName=case(subscriptionId =~ 'Add Subscripton 1 Id here ', 'Add Subscripton 1 Name Here',
subscriptionId =~ 'Add Subscripton 2 Id here ', 'Add Subscripton 2 Name Here'
subscriptionId =~ 'Add Subscripton 3 Id here ', 'Add Subscripton 3 Name Here'
,subscriptionId) // You can in similar way to add more
| summarize count() by SubscriptionName
输出:
就是这样!