概述
我想将查询从使用表
Virtual machines \ Perf
转换为 Virtual machines \ InsightsMetrics
。
现状
我使用以下查询来获取一个订阅中所有 Azure 虚拟机上的可用磁盘空间的概览:
Perf
| where ObjectName == "LogicalDisk" or // the object name used in Windows records
ObjectName == "Logical Disk" // the object name used in Linux records
| where CounterName == "Free Megabytes"
| where InstanceName != "_Total"
| where InstanceName !startswith "HarddiskVolume"
| summarize arg_max(TimeGenerated, *) by CounterPath // arg_max over TimeGenerated returns the latest record
| project TimeGenerated, Drive=InstanceName, bin(FreeGB = CounterValue / 1024, 0.1), Computer
| join kind=inner (Perf
| where ObjectName == "LogicalDisk" or // the object name used in Windows records
ObjectName == "Logical Disk" // the object name used in Linux records
| where CounterName == "% Free Space"
| where InstanceName != "_Total"
| where InstanceName !startswith "HarddiskVolume"
| summarize arg_max(TimeGenerated, *) by CounterPath // arg_max over TimeGenerated returns the latest record
| project TimeGenerated, Drive=InstanceName, bin(FreePercent = CounterValue, 1), Computer)
on Drive, Computer
| project TimeGenerated, Computer, Drive, FreeGB, FreePercent
| order by Computer asc
返回类似这样的内容:
时间生成 | 电脑 | 开车 | FreeGB | 免费百分比 |
---|---|---|---|---|
2021.8.23, 14:33:35.557 | 主机名.domain.com | C: | 81.9 | 64 |
2021.8.23, 14:33:14.857 | 主机名.domain.com | D: | 73.6 | 98 |
如果
Windows Performance counters
由 Log Analytics agent
聚集,则效果很好。
目标
我注意到表
VM Insights
中的InsigtsMetrics
已经收集了类似的数据。现在我想转换我的查询,这样我就可以使用这个 Virtual machines \ InsightsMetrics
表来获得相同的结果,这意味着我可以停止通过 Log Analytics agent
收集计数器。
如果我在该表中查询一个包含我需要的计数器和列的虚拟机,结果如下所示(它与上面的主机不同):
时间生成 | 电脑 | 命名空间 | 姓名 | 瓦尔 | 标签 |
---|---|---|---|---|---|
2021 年 8 月 23 日上午 7:59:57.000 | 主机名.domain.com | 逻辑磁盘 | 自由空间MB | 73,375 | {"vm.azm.ms/mountId":"C:","vm.azm.ms/diskSizeMB":129545.99609375} |
2021 年 8 月 23 日上午 7:59:57.000 | 主机名.domain.com | 逻辑磁盘 | 可用空间百分比 | 56.641 | {"vm.azm.ms/mountId":"C:"} |
我在使用这些标签进行连接和总结时确实遇到了一些麻烦。有没有办法将这些标签转换为常规列或者我应该如何处理这个问题?
解释
上面的查询使用了我在网上找到的片段(我不知道来源),并已进行调整以满足我的需求。它的性能可能不是最高的,但很少会执行(每周一次左右),并且只有在安装了适当的监控之后才会执行。
我现在能够通过使用
Virtual machines \ InsightsMetrics
来转换查询以使用表 parse_json
,如此处所述
什韦塔·洛达
这是我的查询:
InsightsMetrics
| where Name == 'FreeSpaceMB'
| summarize arg_max(TimeGenerated, *) by Tags, Computer
| extend Drive = tostring(parse_json(Tags)["vm.azm.ms/mountId"])
| extend Size = toreal(parse_json(Tags)["vm.azm.ms/diskSizeMB"])
| project TimeGenerated, Computer, Drive, bin(SizeGB = Size / 1024, 0.1), bin(FreeGB = Val / 1024, 1)
| join kind=inner (InsightsMetrics
| where Name == "FreeSpacePercentage"
| summarize arg_max(TimeGenerated, *) by Tags, Computer
| extend Drive = tostring(parse_json(Tags)["vm.azm.ms/mountId"])
| project TimeGenerated, Computer, Drive, bin(FreePercent = Val, 1.1))
on Computer, Drive
| project TimeGenerated, Computer, Drive, SizeGB, FreeGB, FreePercent
| order by Computer asc
结果如下所示:
时间生成 | 电脑 | 开车 | 尺寸GB | FreeGB | 免费百分比 |
---|---|---|---|---|---|
2021 年 8 月 24 日,06:33:27.000 | 主机名.domain.com | C: | 126.5 | 102 | 80.3 |
您是否针对日志分析工作区、VM 日志或 Azure 资源图运行查询?