VMware Cloud Community
MartinO70
Contributor
Contributor
Jump to solution

5 min VM time samples where CPU ready => 5%

Hi

I need help creating a script that extracts every recorded occurrence of VM CPU ready => 5% during the past 24 hours.

Example output:

DateTimeClusterNameVMNameCPURdy
2015-06-16 03:40:00Cluster1VM16.2
2015-06-16 03:45:00Cluster1VM15.6
2015-06-16 08:15:00Cluster1VM17.6
2015-06-16 15:45:00Cluster3VM211.3
2015-06-16 19:05:00Cluster2VM38.1

I'm struggling to work out the most efficient way to do this, considering I need to pull this info daily from 100+ clusters and 20.000+ VM's.

Can anyone help?

Thanks,
Martin

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can try something like this

$start = (Get-Date).AddDays(-1)

$stat = 'cpu.ready.summation'

$tgtPCT = 0.1

$clusterName = 'MyCluster'

$vms = Get-Cluster -Name $clusterName | Get-VM

Get-Stat -Entity $vms -Stat $stat -Start $start -Instance '' |

Group-Object -Property {$_.Entity.Name} | %{

    $_.Group | %{

        $readyPCT = $_.Value/($_.IntervalSecs*100)

        if($readyPCT -ge $tgtPCT){

            $_ | Select Timestamp,

                @{N='Cluster';E={$clusterName}},

                @{N='VM';E={$_.Entity.Name}},

                @{N='CPURdy';E={[math]::Round($readyPCT,1)}}

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You can try something like this

$start = (Get-Date).AddDays(-1)

$stat = 'cpu.ready.summation'

$tgtPCT = 0.1

$clusterName = 'MyCluster'

$vms = Get-Cluster -Name $clusterName | Get-VM

Get-Stat -Entity $vms -Stat $stat -Start $start -Instance '' |

Group-Object -Property {$_.Entity.Name} | %{

    $_.Group | %{

        $readyPCT = $_.Value/($_.IntervalSecs*100)

        if($readyPCT -ge $tgtPCT){

            $_ | Select Timestamp,

                @{N='Cluster';E={$clusterName}},

                @{N='VM';E={$_.Entity.Name}},

                @{N='CPURdy';E={[math]::Round($readyPCT,1)}}

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MartinO70
Contributor
Contributor
Jump to solution

Many thanks LucD,

I'll try that out ASAP but have a couple of questions first please Smiley Happy

1.

If I'd like to divide the cpu ready value with number of vCPU's assigned, would this change be correct?:

$readyPCT = $_.Value/($_.IntervalSecs*100)/$_.entity.numcpu

(I've read somewhere that the "aggregation instance CPU ready value" should be divided by the number of vCPUs. Aggregation CPU ready of 20% might be misleadingly bad on an 8 vCPU system (only 2.5% per vCPU). I might be wrong, what's your opinion?)

2.

If I run the same script against several clusters, would this change work?

@{N='Cluster';E={$_.entity.vmhost.parent.name}},

Thanks,

Martin

0 Kudos
LucD
Leadership
Leadership
Jump to solution

1. Yes and no.

The division is indeed is indeed required to get a better view on the overall RDY% for the VM.

But it would also be useful, in some cases, to check if there are 1 or more vCPU with high RDY%, while the rest of vCPU has a low RDY%.

This could be for example a single-threaded process running in the VM.

2. Yes, that should work


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

MartinO70
Contributor
Contributor
Jump to solution

Much appreciated, many thanks!

0 Kudos