To retrieve disk space utilization (the actual used and free space), you'll need to interact with the VM operating system itself.
To accomplish this, you can use Azure VM Custom Script Extension. This will run a script inside the VM to check the disk utilization directly. Here's how you can do that:
- Using the Custom Script Extension: You can use the Custom Script Extension for Windows or Linux VMs to run a script on the VM that checks the disk space usage. For Windows, you can use PowerShell inside the VM to check disk utilization:
You can then use the Custom Script Extension to deploy and run this script on your Azure VM.Get-WmiObject Win32_LogicalDisk | Select-Object DeviceID, MediaType, @{Name="Used(GB)"; Expression={[math]::round($_.Size/1GB - $_.FreeSpace/1GB,2)}}, @{Name="Free(GB)"; Expression={[math]::round($_.FreeSpace/1GB,2)}}, @{Name="Size(GB)"; Expression={[math]::round($_.Size/1GB,2)}}
- For Linux, you could use a bash script to check the disk space:
df -h | grep -E '^/dev/'
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin