Available Memory percentage and CPU utilization on Virtual Machines

%3CLINGO-SUB%20id%3D%22lingo-sub-1834702%22%20slang%3D%22en-US%22%3EAvailable%20Memory%20percentage%20and%20CPU%20utilization%20on%20Virtual%20Machines%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1834702%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EI%20trying%20to%20get%20list%20of%20the%20VMs%20that%20have%20available%20memory%20below%2020%25%20and%20CPU%20Utilization%20above%2050%25.%20I%20have%20this%20below%20two%20queries%20for%20Memory%20and%20CPU.%20Can%20you%20please%20suggest%20on%20how%20to%20join%20both%20queries.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPerf%0A%7C%20where%20%20ObjectName%20%3D%3D%20%22Processor%22%20and%20CounterName%20%3D%3D%20%22%25%20Processor%20Time%22%20and%20InstanceName%20%3D%3D%20%22_Total%22%0A%7C%20summarize%20AggregatedValue%20%3D%20avg(CounterValue)%20by%20Computer%2C%20bin(TimeGenerated%2C%201h)%0A%7C%20where%20AggregatedValue%20%26gt%3B50%0A%7C%20render%20table%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Elet%20free_memory_percent%20%3D%20Perf%0A%7C%20where%20CounterName%20%3D%3D%20%22%25%20Committed%20Bytes%20In%20Use%22%0A%7C%20summarize%20arg_max(TimeGenerated%2C%20CounterValue)%20by%20Computer%0A%7C%20project%20TimeGenerated%2C%20Computer%2C%20free_memory_percent%3D100-CounterValue%3B%0Alet%20free_memory_gigs%20%3D%20Perf%0A%7C%20where%20CounterName%20%3D%3D%20%22Available%20MBytes%22%0A%7C%20summarize%20arg_max(TimeGenerated%2C%20CounterValue)%20by%20Computer%0A%7C%20project%20TimeGenerated%2C%20Computer%2C%20free_memory_GB%3DCounterValue%2F1024%3B%0Afree_memory_gigs%20%0A%7C%20join%20kind%3D%20innerunique(free_memory_percent)%20on%20Computer%0A%7C%20where%20free_memory_percent%20%26gt%3B%2080%0A%7C%20project%20TimeGenerated%2C%20Computer%2C%20free_memory_percent%2C%20free_memory_GB%2C%20Total_GB%3D(free_memory_GB*100)%2Ffree_memory_percent%0A%7C%20sort%20by%20free_memory_percent%20asc%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThanks%2C%3C%2FP%3E%0A%3CP%3ERuheena%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1834702%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELog%20Analytics%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1841993%22%20slang%3D%22en-US%22%3ERe%3A%20Available%20Memory%20percentage%20and%20CPU%20utilization%20on%20Virtual%20Machines%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1841993%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F388899%22%20target%3D%22_blank%22%3E%40Ruheena%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20make%20it%20most%20%22elegant%22%2C%20prepend%20your%20queries%20with%20a%20let%20statement%20for%20the%20CPU%20usage%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Elet%20CPU_usage%3D%0APerf%0A%7C%20where%20%20ObjectName%20%3D%3D%20%22Processor%22%20and%20CounterName%20%3D%3D%20%22%25%20Processor%20Time%22%20and%20InstanceName%20%3D%3D%20%22_Total%22%0A%7C%20summarize%20AggregatedValue%20%3D%20avg(CounterValue)%20by%20Computer%2C%20bin(TimeGenerated%2C%201h)%0A%7C%20where%20AggregatedValue%20%26gt%3B50%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThen%2C%20append%20your%20existing%20memory%20query%20with%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%7C%20join%20CPU_usage()%20on%20Computer%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHTH%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

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

1 Reply

@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