我有以下查询,帮助我从虚拟机磁盘的数据
InsightsMetrics
| where Namespace == "LogicalDisk"
| extend Tags = todynamic(Tags)
| extend Drive=tostring(todynamic(Tags)["vm.azm.ms/mountId"])
| extend DiskSize=tostring(todynamic(Tags)["vm.azm.ms/diskSizeMB"])
| summarize
Free_space_percentage = avgif(Val, Name == 'FreeSpacePercentage'),
Free_Gigabytes = avgif(Val, Name == 'FreeSpaceMB') /1024
by Computer, Drive
| join (
InsightsMetrics
| where Namespace == "LogicalDisk"
| extend Tags = todynamic(Tags)
| extend DiskSize=tostring(todynamic(Tags)["vm.azm.ms/diskSizeMB"])
| extend Drive=tostring(todynamic(Tags)["vm.azm.ms/mountId"])
) on Computer, Drive
| where DiskSize has "."
| summarize by Computer,Drive , Free_space_percentage, Free_Gigabytes, DiskSize
问题是现在DiskSize以兆字节显示,而其余的都以千兆字节显示。我现在已经尝试了几个小时,试图将其转换为gigas,但没有运气。有人可以帮助我在哪里,我应该如何做我的转换在我的查询?
似乎您的问题不在于将MB转换为GB,而在于构建一个查询,该查询将为您提供平均值以及磁盘大小。
假设磁盘的大小在查询期间没有改变,take_any()将完成此操作。
InsightsMetrics
// | where TimeGenerated between(datetime(2022-04-01) .. datetime(2022-04-01 00:00:10))
| where Namespace == "LogicalDisk"
| extend Tags = todynamic(Tags)
| extend Drive = tostring(Tags["vm.azm.ms/mountId"])
| extend diskSizeGB = Tags["vm.azm.ms/diskSizeMB"]/1024.0
| summarize
avg_FreeSpacePercentage = avgif(Val, Name == 'FreeSpacePercentage')
,avg_FreeSpaceGB = avgif(Val, Name == 'FreeSpaceMB') /1024
,take_any(diskSizeGB)
by Computer, Drive
计算机 | 驱动器 | avg_FreeSpacePercentage | avg_FreeSpaceGB | diskSizeGB | DC00.na.contosohotels.com | C: | 74.9538803100586 | 94.8232421875 | 126.50976181030273 |
---|---|---|---|---|
DC00.na.contosohotels.com | D: | 91.4168853759766 | 14.6240234375 | 15.998043060302734 |
SQL12.na.contosohotels.com | C: | 57.7019577026367 | 72.998046875 | 126.50976181030273 |
SQL12.na.contosohotels.com | D: | 92.02197265625 | 29.4443359375 | 31.998043060302734 |
SQL12.na.contosohotels.com | F: | 99.9144668579102 | 127.7626953125 | 127.87304306030273 |
AppBE01.na.contosohotels.com | C: | 73.2973098754883 | 92.7275390625 | 126.50976181030273 |
AppBE01.na.contosohotels.com | D: | 91.3375244140625 | 14.611328125 | 15.998043060302734 |