Get VM Status from Custom Query

MrB1963 61 Reputation points
2023-03-24T13:37:16.66+00:00

Hello,

I have a custom query to tell me when a vm has a certain percentage of disk space. It is set to 90 right now for testing. Is there a way to Return a value of Health if nothing is found and Not-Healthy if this threshold is meant. I am new tot his and trying to figure this out so any help would be appreciated.



Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,798 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,114 questions
{count} votes

Accepted answer
  1. Andrew Blumhardt 9,491 Reputation points Microsoft Employee
    2023-03-24T17:19:45.54+00:00

    Something like this??

    let HealthyPercent = 90;
    InsightsMetrics
    | where Origin == "vm.azm.ms"
    and Namespace == "LogicalDisk" and Name == "FreeSpacePercentage"
    | extend Disk=tostring(todynamic(Tags)["vm.azm.ms/mountId"])
    | where Disk != "D:"
    | summarize Disk_Free_Space = avg(Val) by Computer, Disk, _ResourceId
    | project Computer, Disk, Disk_Free_Space, Status = iif(Disk_Free_Space < HealthyPercent, "Unhealthy", "Healthy")
    

0 additional answers

Sort by: Most helpful