0

Is there a way to get both disk sizes and disk space used in azure?

I can use a query like this and get the percentage or mb used

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

And see disk sizes like this

resources
| where type == "microsoft.compute/disks"
| project properties['diskSizeGB']

But is there a way to see both size of disk and how much space is left?

ProgH
  • 3
  • 3

2 Answers2

0

This query would give you an approximation disk size, though it will never be 100% accurate, but very close

InsightsMetrics
| where Origin == "vm.azm.ms"
 and Namespace == "LogicalDisk" 
 | where Name in ("FreeSpaceMB", "FreeSpacePercentage")
| extend Disk=tostring(todynamic(Tags)["vm.azm.ms/mountId"])
| summarize arg_max(TimeGenerated, Val) by Computer, Name, Disk, _ResourceId
| extend Packed = bag_pack(Name, Val) 
| project TimeGenerated, Computer, Disk, _ResourceId, Packed
| summarize Packed = make_bag(Packed) by TimeGenerated, Computer, Disk, _ResourceId
| evaluate bag_unpack(Packed) : (TimeGenerated:datetime , Computer:string, Disk:string, _ResourceId:string, FreeSpaceMB:long, FreeSpacePercentage:decimal)
| extend DiskSizeGB = ceiling((todecimal(FreeSpaceMB) / (FreeSpacePercentage / todecimal(100))) /1024)

Another way you could calculate it is by taking your two original queries and using Azure Workbooks to query Log Analytics and Azure Resource Graph and then merge the results https://learn.microsoft.com/en-us/azure/azure-monitor/visualize/workbooks-data-sources#merge

TheAlistairRoss
  • 305
  • 1
  • 3
0

But is there a way to see both size of disk and how much space is left?

You can use below Kusto Query Language that retrieves both the disk sizes and used disk space also free space for each disk.

KQL Query:

Perf | where ObjectName == "LogicalDisk" and CounterName == "Free Megabytes" 
| summarize TotalDiskSpace_GB = (max(CounterValue) + sum(CounterValue)/1024), UsedDiskSpace_GB = (sum(CounterValue)/1024),Freespace_GB = ((max(CounterValue) + sum(CounterValue))-sum(CounterValue)/1024) by Computer, InstanceName

Output:

enter image description here

Venkat V
  • 2,197
  • 1
  • 1
  • 10