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

如何在Azure Kusto查询中裁剪Azure资源ID优化图表显示

解决方案

你可以通过Kusto提供的字符串处理函数裁剪_ResourceId,仅保留末尾的Web应用名称,优化图表展示效果,以下是两种常用实现方式:

方案1:使用parse算子(推荐,适配所有Azure资源ID格式)

该方案不需要硬编码前缀内容,不管订阅ID、资源组名称如何变化,都能稳定提取Web应用名称,兼容性最高。
修改后的完整查询语句如下:

AppServiceAppLogs
| where TimeGenerated >= now(-1h) and Level == "Error"
| project TimeGenerated , _ResourceId , Source, ResultDescription
// 解析_ResourceId提取末尾的站点名称
| parse _ResourceId with * "/sites/" SiteName
| summarize ErrorsLogged = count() by SiteName
| order by ErrorsLogged
| render piechart 

parse _ResourceId with * "/sites/" SiteName的逻辑是匹配_ResourceId中/sites/字符串后的所有内容,赋值给新的SiteName字段,正好对应你需要的Web应用名称。

方案2:使用split分割字符串(适合固定格式场景)

如果你确认所有_ResourceId的结构固定,也可以用split函数按/分割资源ID,直接取数组最后一位元素:

AppServiceAppLogs
| where TimeGenerated >= now(-1h) and Level == "Error"
| project TimeGenerated , _ResourceId , Source, ResultDescription
// 按/分割资源ID,取最后一个元素作为站点名
| extend SiteName = split(_ResourceId, '/')[-1]
| summarize ErrorsLogged = count() by SiteName
| order by ErrorsLogged
| render piechart 

两种方案执行后,饼图的分类标签都会显示为Web应用的名称,不会再出现超长的完整资源ID。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 07:24:00