Logs Query for Exact Disk Space Amount Used

Jennings, Aaron Christopher 0 Reputation points
2024-07-16T15:46:11.13+00:00

Hello, I am looking to improve upon an example query that outputs free disk percentage for an Azure machine. I would like for it to also display in the project the used percentage instead of free percentage, used disk space (in GB), and total disk space. AI hasn't been so fortunate in giving any correct syntax/variables/etc.

Thank you

InsightsMetrics
| where Namespace == "LogicalDisk" 
| where Name == "FreeSpacePercentage" 
| extend Disk=tostring(todynamic(Tags)["vm.azm.ms/mountId"]) 
| summarize arg_max(TimeGenerated, *) by Disk, Computer
| extend TimeGenerated_EST = datetime_utc_to_local(TimeGenerated, 'America/New_York') 
| project TimeGenerated_EST, Disk, Computer, Val
| where Val > 30
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Clive Watson 7,951 Reputation points MVP Volunteer Moderator
    2024-07-16T19:13:26.2466667+00:00

    This is a query I saved (source: https://stackoverflow.com/questions/76372077/how-to-find-both-disk-size-and-disk-space-used-in-azure). It calculates the size but should be close enough in most cases, you'll just have to calculate the used % from this

    InsightsMetrics
    | where 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)
    | extend freeSpaceGB = FreeSpaceMB /1024
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.