VMware Cloud Community
MarkusLanderti1
VMware Employee
VMware Employee

Performance counters from VM's in Cluster

Dear Forum,

I am seeking out for a Script, that fetches the following performance counters from all VM's inside a Cluster at a given runtime.

1. VM Name

2. CPU load in percent  average

3. CPU load MHZ average

4. Number of assigned CPU Cores (static value)

Since getting this values in parallel will be a time consuming task, I had the idea to split it on a 'per cluster basis' and execute them paralelly. Performance is kind of a deal here.

I already have a basic script that allows me to connect to all Hosts of a certain Cluster, but I'm missing the whole 'get values and pack it into variables' part 🙂

I'm sure that somebody has got something quite similar that he/she maybe want's to share.

THanks in advance,

Kind regards, Markus

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

Can you expand on the "... split it on a 'per cluster basis' and execute them paralelly"?

Are you looking at Start-Job?

Or running the script for each cluster on different machines?

It could also help if you share what you already have.


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

Reply
0 Kudos
MarkusLanderti1
VMware Employee
VMware Employee

Hi LucD.

Sure - sorry if that caused confusion. I just meant that I would build 3 scripts with the corresponding clusternames inside of them and execute em paralelly, and not calling each cluster after another from within the script. ClusterName itself can be a variable in the Script. This should lead to a better overall execution time. If there is some kind of 'instanced execution' in PS that I'm not aware of yet, that would be also a thing to consider.

What I've got so far: Declaration of the target vCenter and Clustername and connecting to it via Connect-VIServer $vcenter. Not pasting the code since this is basic.

What I'm missing:

* Select cluster by $clustername

* Fetch the values from my 1st post from each VM inside this Cluster.

* Return them in variables, starting with a timestamp.

I attached a screenshot of the desired 'return' format.

Kind regards, Markus

Reply
0 Kudos
LucD
Leadership
Leadership

Try something like this

$clusterName = 'Cluster'

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

$sStat = @{

    Entity = $vms

    Stat = 'cpu.usage.average','cpu.usagemhz.average'

    Realtime = $true

    MaxSamples = 1

    Instance = ''

}


Get-Stat @sStat |

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

ForEach-Object -Process {

    New-Object -TypeName PSObject -Property ([ordered]@{

        VM = $group.Name

        CPUAvg = $group.Group | where{$_.MetricId -eq 'cpu.usage.average'} | Select -ExpandProperty Value

        CPUAvgMhz = $group.Group | where{$_.MetricId -eq 'cpu.usagemhz.average'} | Select -ExpandProperty Value

        Cores = $group.Group[0].Entity.NumCpu

    })

}


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

Reply
0 Kudos
MarkusLanderti1
VMware Employee
VMware Employee

Wow - cool! Thanks for including that ForEach-Object -Process { part, I think that's exactly what I was looking for 🙂 🙂  Will try and then give Feedback!
Reply
0 Kudos