Forum Discussion

Ruheena's avatar
Ruheena
Icon for Microsoft rankMicrosoft
Oct 29, 2020

Available Memory percentage and CPU utilization on Virtual Machines

Hello,

I trying to get list of the VMs that have available memory below 20% and CPU Utilization above 50%. I have this below two queries for Memory and CPU. Can you please suggest on how to join both queries.

Perf
| where  ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
| summarize AggregatedValue = avg(CounterValue) by Computer, bin(TimeGenerated, 1h)
| where AggregatedValue >50
| render table

 

let free_memory_percent = Perf
| where CounterName == "% Committed Bytes In Use"
| summarize arg_max(TimeGenerated, CounterValue) by Computer
| project TimeGenerated, Computer, free_memory_percent=100-CounterValue;
let free_memory_gigs = Perf
| where CounterName == "Available MBytes"
| summarize arg_max(TimeGenerated, CounterValue) by Computer
| project TimeGenerated, Computer, free_memory_GB=CounterValue/1024;
free_memory_gigs 
| join kind= innerunique(free_memory_percent) on Computer
| where free_memory_percent > 80
| project TimeGenerated, Computer, free_memory_percent, free_memory_GB, Total_GB=(free_memory_GB*100)/free_memory_percent
| sort by free_memory_percent asc

Thanks,

Ruheena

  • Ruheena 

    To make it most "elegant", prepend your queries with a let statement for the CPU usage:

    let CPU_usage=
    Perf
    | where  ObjectName == "Processor" and CounterName == "% Processor Time" and InstanceName == "_Total"
    | summarize AggregatedValue = avg(CounterValue) by Computer, bin(TimeGenerated, 1h)
    | where AggregatedValue >50;

    Then, append your existing memory query with:

    | join CPU_usage() on Computer

     

    HTH

Resources