如何将Azure VM磁盘剩余空间查询从Perf表迁移至InsightsMetrics表
适配InsightsMetrics表的磁盘剩余空间查询方案
你可以使用todynamic()函数将Tags字段从JSON字符串转换为动态类型,直接提取其中的mount属性作为盘符列,以下是和原有逻辑完全等效的查询:
// 提取剩余容量指标 InsightsMetrics | where Namespace == "LogicalDisk" | where Name == "Free Megabytes" | extend Tags = todynamic(Tags) | extend Drive = tostring(Tags.mount) | where Drive != "_Total" | where Drive !startswith "HarddiskVolume" | summarize arg_max(TimeGenerated, *) by Drive, Computer | project TimeGenerated, Computer, Drive, bin(FreeGB = Val / 1024, 0.1) // 关联剩余百分比指标 | join kind=inner ( InsightsMetrics | where Namespace == "LogicalDisk" | where Name == "% Free Space" | extend Tags = todynamic(Tags) | extend Drive = tostring(Tags.mount) | where Drive != "_Total" | where Drive !startswith "HarddiskVolume" | summarize arg_max(TimeGenerated, *) by Drive, Computer | project TimeGenerated, Computer, Drive, bin(FreePercent = Val, 1) ) on Computer, Drive | project TimeGenerated, Computer, Drive, FreeGB, FreePercent | order by Computer asc
该查询自动兼容Windows、Linux系统的磁盘指标采集,无需额外区分对象名差异,输出字段和原有查询完全一致,无需依赖Log Analytics代理额外采集性能计数器。
内容的提问来源于stack exchange,提问作者Manu
相关产品推荐
相关产品推荐

