在KQL查询中将磁盘大小从mb转换为gb



我有以下查询,帮助我从虚拟机磁盘的数据

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
tbody> <<tr>
计算机驱动器avg_FreeSpacePercentageavg_FreeSpaceGBdiskSizeGB
DC00.na.contosohotels.comC:74.953880310058694.8232421875126.50976181030273
DC00.na.contosohotels.comD:91.416885375976614.624023437515.998043060302734
SQL12.na.contosohotels.comC:57.701957702636772.998046875126.50976181030273
SQL12.na.contosohotels.comD:92.0219726562529.444335937531.998043060302734
SQL12.na.contosohotels.comF:99.9144668579102127.7626953125127.87304306030273
AppBE01.na.contosohotels.comC:73.297309875488392.7275390625126.50976181030273
AppBE01.na.contosohotels.comD:91.337524414062514.61132812515.998043060302734

相关内容

  • 没有找到相关文章

最新更新