VMware Cloud Community
Jquintero06
Contributor
Contributor
Jump to solution

Report CPU, Core, and VMs

Hello everyone,

I would like to get a report of the hosts contained in a cluster using PowerCLI containing the following information:

Total CPU
Total CPU Used
Total CPU free
Total Core
Total Core Used
Total Core free
Total VMs that could be installed using configuration 1:4

I have been able to get the total, used and free CPUs, but I can't get the cores information and VMs

Could you please enlighten me and show me how to do it?

 

Reply
0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I moved the Get-VM inside the loop, and it seems to work for me

$vmhosts=get-cluster $cluster | Get-VMHost $vmhosts

$Output=@()

ForEach ($vmhost in $vmhosts)
{
$vms = Get-VM -Location $vmhost

$vcpus=0
$ratio=$null
$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.NumCpuCores
$vms | ForEach {$vcpus+=$_.numcpu}
   if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}

   $temp= New-Object psobject
   $temp| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name
   $temp| Add-Member -MemberType Noteproperty "Cluster" -value $vmhost.parent.name
   $temp| Add-Member -MemberType Noteproperty "PhysicalThreads" -Value  $Hostthreads
   $temp| Add-Member -MemberType Noteproperty "vCPUs" -Value $vcpus
   $temp| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio
   $Output+=$temp
}

$output


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

View solution in original post

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-Cluster -PipelineVariable cluster | ForEach-Object -Process {
  Get-VMHost -Location $cluster |
    ForEach-Object -Process {
      $numCpuSum = (Get-VM -Location $_ | Measure-Object -Property NumCpu -Sum).Sum
      New-Object -TypeName PSObject -Property @{
        Cluster         = $cluster.Name
        VMHost          = $_.Name
        PhysicalThreads = $_.ExtensionData.Hardware.CpuInfo.NumCpuCores
        vCPUs           = $numCpuSum
        Ratio           = if ($numCpuSum -gt 0) {
          "$("{0:N2}" -f ($numCpuSum/$_.ExtensionData.Hardware.CpuInfo.NumCpuCores))" + ":1"
        }
    }
  }
}


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

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

What do you mean by "cores used"?
Is that the number of vCPU assigned to VMs running in that cluster?
Or do you mean realtime performance metrics showing core cpu utilisation?


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

Reply
0 Kudos
Jquintero06
Contributor
Contributor
Jump to solution

Sorry I explained wrong, what I intend to do is to make an estimate based on the cores that have the processors and the cores consumed , based on that estimate whose VMs are configured Core per Socket 1:4.

I have created this script but I can't find the error, could you please help me?


param(
[Parameter(Mandatory = $false)]
[String]$cluster,
$vmhosts="*"
)

$vmhosts=get-cluster $cluster | Get-VMHost $vmhosts
$vms=Get-VM

$Output=@()

ForEach ($vmhost in $vmhosts)
{

$vcpus=0
$ratio=$null
$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.NumCpuCores
$vms |Where-Object {$_.vmhost -like $vmhost}|ForEach {$vcpus+=$_.numcpu}
if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}

$temp= New-Object psobject
$temp| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name
$temp| Add-Member -MemberType Noteproperty "Cluster" -value $vmhost.parent.name
$temp| Add-Member -MemberType Noteproperty "PhysicalThreads" -Value $Hostthreads
$temp| Add-Member -MemberType Noteproperty "vCPUs" -Value $vcpus
$temp| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio
$Output+=$temp

}

$output

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I moved the Get-VM inside the loop, and it seems to work for me

$vmhosts=get-cluster $cluster | Get-VMHost $vmhosts

$Output=@()

ForEach ($vmhost in $vmhosts)
{
$vms = Get-VM -Location $vmhost

$vcpus=0
$ratio=$null
$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.NumCpuCores
$vms | ForEach {$vcpus+=$_.numcpu}
   if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}

   $temp= New-Object psobject
   $temp| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name
   $temp| Add-Member -MemberType Noteproperty "Cluster" -value $vmhost.parent.name
   $temp| Add-Member -MemberType Noteproperty "PhysicalThreads" -Value  $Hostthreads
   $temp| Add-Member -MemberType Noteproperty "vCPUs" -Value $vcpus
   $temp| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio
   $Output+=$temp
}

$output


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

Reply
0 Kudos
Jquintero06
Contributor
Contributor
Jump to solution

Hi,

I get the following error:

Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is
not null or empty, and then try the command again.
At D:\vCollect-Reports\Untitled1.ps1:1 char:44
+ $vmhosts=get-cluster $cluster | Get-VMHost $vmhosts
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

 

I have updated to the latest version, but it gives the same error.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I left out your parameter definitions, you will have to add them

param(
[Parameter(Mandatory = $false)]
[String]$cluster,
$vmhosts="*"
)


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

Reply
0 Kudos
Jquintero06
Contributor
Contributor
Jump to solution

What parameters should I change so that the script runs on all vCenter clusters, and not one by one?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-Cluster -PipelineVariable cluster | ForEach-Object -Process {
  Get-VMHost -Location $cluster |
    ForEach-Object -Process {
      $numCpuSum = (Get-VM -Location $_ | Measure-Object -Property NumCpu -Sum).Sum
      New-Object -TypeName PSObject -Property @{
        Cluster         = $cluster.Name
        VMHost          = $_.Name
        PhysicalThreads = $_.ExtensionData.Hardware.CpuInfo.NumCpuCores
        vCPUs           = $numCpuSum
        Ratio           = if ($numCpuSum -gt 0) {
          "$("{0:N2}" -f ($numCpuSum/$_.ExtensionData.Hardware.CpuInfo.NumCpuCores))" + ":1"
        }
    }
  }
}


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

Reply
0 Kudos
Jquintero06
Contributor
Contributor
Jump to solution

Thank you very much!!!!!

Reply
0 Kudos