Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all articles
Browse latest Browse all 9071

Set resource pool CPU limit foreach resource pool

$
0
0

Thecompany have 14hosts and 1500VMs

I decided tochallengethe appointmentof limitsto the resourcepools
The scriptcollects information aboutresourcepools, powered On virtual machine, the total number ofvСPUinto a resourcepooland designatedlimits.
Tocorrect destinationlimitsderived a formula LimitVCPU = (155+420 / [math]::pow($TotVCPU, 0.5 ))*$TotVCPU), ofwhichare considered to belimits. The sum of theselimitswill not exceed90% ofthe CPUof the host, it will beto control thesupply ofthe host.

 

 

NameTotalVCPULimitVCPUESXHostCpuTotalMhzSummLimitCPUCoefficientNewLimitVCPU
RP100srv-esx-011919286192,004200
RP215751152
RP329041812
RP429041812
RP5414602926
RP51947769571

 

 

cls

$watch = [System.Diagnostics.Stopwatch]::StartNew()

$watch.Start() #Start time

 

$myCol = @()

 

$ESXHosts = Get-VMHost

$TotVCPU = 0

$LimitVCPU = 0

$CpuTotalMhz = 0

 

$ii = 0

foreach ($ESXHost in $ESXHosts){

    $SummLimitCPU = 0

    $RPs = Get-ResourcePool -Location $ESXHost | ?{$_.Name -ne "Resources"}

    $i = 0

    foreach($RP in $RPs){

        $VMs = Get-VM -Location $RP  | ?{$_.PowerState -eq "PoweredOn"}

        $TotVCPU = (($VMs | ?{$_.PowerState -eq "PoweredOn"} | select NumCPU | Measure-Object -Property NumCpu -Sum).Sum/1)

        if ($TotVCPU -ne 0)

            {$LimitVCPU = [Math]::Round((155+420 / [math]::pow($TotVCPU, 0.5 ))*$TotVCPU)}

        else {$LimitVCPU = 0}

        if ($LimitVCPU.GetType().FullName -eq "System.Int32")

            {$SummLimitCPU = $SummLimitCPU + $LimitVCPU}

        if ($RP -eq $RPs[-1])

            {$CpuTotalMhz = Get-VMhost -Name $ESXHost | select -ExpandProperty CpuTotalMhz

        if ($SummLimitCPU -ne 0){

            foreach($RP in $RPs){$Coeffecient=[Math]::Round(($CpuTotalMhz / $SummLimitCPU)*0.9,3)}}}

        else

            {$CpuTotalMhz = 0; $Coeffecient=1}

        $Details = "" | Select Name,VMs,TotalVCPU,LimitVCPU,ESXHost,CpuTotalMhz,SummLimitCPU,Coefficient,NewLimitVCPU

        $Details.Name = $RP.Name

        #$Details.VMs = $VMs.Name | Out-String

        $Details.TotalVCPU = $TotVCPU

        $Details.LimitVCPU = $LimitVCPU

        $Details.ESXHost = $ESXHost

        $Details.CpuTotalMhz = $CpuTotalMhz

        $Details.SummLimitCPU = $SummLimitCPU

        $Details.Coefficient = $Coeffecient

        $Details.NewLimitVCPU = [Math]::Round($Coeffecient * $LimitVCPU)

 

#replace Coefficient, SummLimitCPU, NewLimitVCPU in array foreach RP

            $myCol += $Details

        $i = $i+1

    }

    if ($ii -eq 0) {$ii = $ii+($i-1)}

    else {$ii = $ii+$i}

    $point = $ii

    for (;$i -gt 1; $i--)

        {

        $point = $point - 1

        $myCol[$point].Coefficient = $myCol[$ii].Coefficient

        $myCol[$point].SummLimitCPU = $myCol[$ii].SummLimitCPU

        if ($myCol[$point].TotalVCPU -eq 0) {$myCol[$point].NewLimitVCPU = 200}

        else {$myCol[$point].NewLimitVCPU = [Math]::Round($myCol[$ii].Coefficient * $myCol[$point].LimitVCPU)}

 

# set New CPULimit foreach RP

Set-ResourcePool -ResourcePool $myCol[$point].Name -CpuLimitMhz $myCol[$point].NewLimitVCPU

        }

}

$myCol | Export-Csv -Delimiter ";" -Path C:\PowerCLI\Report\ResourcePool.csv

 

$watch.Stop() #Stop time

Write-Host $watch.Elapsed #Run time

 

 

I will be gladto listen tocomments andsuggestions for improvingthe script


Viewing all articles
Browse latest Browse all 9071

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>