Forum Discussion
Azure Monitor disk space used report
Try this
InsightsMetrics | where Origin == "vm.azm.ms" and Namespace == "LogicalDisk" and Name == "FreeSpacePercentage" | extend Disk=tostring(todynamic(Tags)["vm.azm.ms/mountId"]) | summarize Disk_Free_Space = avg(Val) by Computer, Disk, _ResourceId | project Computer, Disk, Disk_Free_Space
- DSM4201Jun 20, 2023Copper Contributor
Hi, thanks for the script but I'm looking for one that show's the disk's used space. I noticed this thread (https://techcommunity.microsoft.com/t5/azure-observability/help-with-disk-query-in-log-analytics/m-p/160239#M440) mentioning using a calculation to find the used space but they were also having issues with the query.
Do you know if I can use another calculation to find the % UsedSpace?
Thanks.
- PradeepDeivaJun 20, 2023Copper Contributor
yea , for Linux - % free space and for Windows - %used space are not direct
check this link - https://www.catapultsystems.com/blogs/calculating-total-memory-and-total-disk-space-in-log-analytics/try adding a last column with the values got from free space and total size - we can calculate the %
hope this helps
- DSM4201Jun 26, 2023Copper Contributor
I'm a little closer now. I was wondering if theirs a way to show the output without the "_". So instead of seeing "Used_Space_Percentage" the output would show "Used Space %"?
Also is there a way to show the output without the numbers after the decimal point? I used round in the query but I have to keep at least two spaces. Here's what I have for the query so far;
InsightsMetrics
| where TimeGenerated >= ago(1h)
| where Origin == "vm.azm.ms" and Namespace == "LogicalDisk" and Name == "FreeSpaceMB"
| extend Disk = tostring(todynamic(Tags)["vm.azm.ms/mountId"]),
Disk_Size_GB =(todynamic(Tags)["vm.azm.ms/diskSizeMB"]) / 1024
| summarize Disk_Free_Space_GB = avg(Val) / 1024 by Computer, Disk, Disk_Size_GB, _ResourceId
| extend Used_Space_GB = Disk_Size_GB - Disk_Free_Space_GB
| extend Used_Space_Percentage = round((todouble(Used_Space_GB / Disk_Size_GB) * 100) ,2)
| where Used_Space_Percentage >= 90
| project Computer, Disk, Disk_Size_GB, Disk_Free_Space_GB, Used_Space_GB, Used_Space_PercentageThanks.