#add-pssnapin VMware.VimAutomation.Core
param(
$vm=$(throw "Provide the vm server name as is in the Vsphere"),
$vcenter=$(throw "Provide the Vcenter name example: VCenter Server"),
$port=$(throw "Provide the port number to connect example: 443"),
$user=$(throw "Provide the read-only user name to connect to Vcenter example: Domain\username"),
$pass=$(throw " Provide the password to connect to the vCenter password")
)
#$vm = "VMware Server"
#$vcenter = "Vcenter Server"
#$port = 443
#$user = "Domain\username"
#$pass = "password"
$statcpuready = 0
add-pssnapin VMware.VimAutomation.Core
#Write-Host $vm $vcenter $port $user $pass
$certresponse = Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$return = Connect-VIServer -Server $vcenter -Port $port -User $user -Password $pass
$vcpu = (Get-VM -Name $vm).NumCpu
[int]$statcpuready = ((Get-VM -Name $vm | Get-Stat -Stat cpu.ready.summation -Realtime| Where {$_.Instance -eq ""}| Select-Object -First 15 value | Measure-Object -Property Value -Average).Average)
#Write-Host "No. of vCPU:"$vcpu ",CPU ready summation in (ms):" $statcpuready
if ( $vcpu -eq 4 ) # warning 4000ms Critical 7000ms
{
$warnlevel = 20
$warnlevelms = 4000
$criticallevel = 35
$criticallevelms = 7000
}
if ( $vcpu -eq 2 ) # warning 2000ms critical 3500ms
{
$warnlevel = 10
$warnlevelms = 2000
$criticallevel = 17
$criticallevelms = 3500
}
if ( $vcpu -eq 1 ) # warning 1000ms critical 1500ms
{
$warnlevel = 5
$warnlevelms = 1000
$criticallevelms = 1500
}
$statcpureadyper = (($statcpuready) / (20*1000))*100
#Write-Host $statcpureadyper
if ($statcpureadyper -gt $criticallevel) {
Write-Host "CRITICAL:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPUReadySummation(Avg5mins)(ms)="$statcpuready";"$warnlevelms";"$criticallevelms
exit(2)
} elseif ($statcpureadyper -gt $warnlevel) {
Write-Host "WARNING:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPUReadySummation(Avg5mins)(ms)="$statcpuready";"$warnlevelms";"$criticallevelms
exit(1)
} elseif ($statcpureadyper -lt $warnlevel) {
Write-Host "OK:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPUReadySummation(Avg5mins)(ms)="$statcpuready";"$warnlevelms";"$criticallevelms
#Write-Host "OK:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPU Ready (Avg 5mins)%="$statcpureadyper"%;"$warnlevel";"$criticallevel";0;100;CPU Ready Summation in (ms)(Avg 5mins)="$statcpuready";0;0"
exit(0)
}
disconnect-viserver -confirm:$false
param(
$vm=$(throw "Provide the vm server name as is in the Vsphere"),
$vcenter=$(throw "Provide the Vcenter name example: VCenter Server"),
$port=$(throw "Provide the port number to connect example: 443"),
$user=$(throw "Provide the read-only user name to connect to Vcenter example: Domain\username"),
$pass=$(throw " Provide the password to connect to the vCenter password")
)
#$vm = "VMware Server"
#$vcenter = "Vcenter Server"
#$port = 443
#$user = "Domain\username"
#$pass = "password"
$statcpuready = 0
add-pssnapin VMware.VimAutomation.Core
#Write-Host $vm $vcenter $port $user $pass
$certresponse = Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$return = Connect-VIServer -Server $vcenter -Port $port -User $user -Password $pass
$vcpu = (Get-VM -Name $vm).NumCpu
[int]$statcpuready = ((Get-VM -Name $vm | Get-Stat -Stat cpu.ready.summation -Realtime| Where {$_.Instance -eq ""}| Select-Object -First 15 value | Measure-Object -Property Value -Average).Average)
#Write-Host "No. of vCPU:"$vcpu ",CPU ready summation in (ms):" $statcpuready
if ( $vcpu -eq 4 ) # warning 4000ms Critical 7000ms
{
$warnlevel = 20
$warnlevelms = 4000
$criticallevel = 35
$criticallevelms = 7000
}
if ( $vcpu -eq 2 ) # warning 2000ms critical 3500ms
{
$warnlevel = 10
$warnlevelms = 2000
$criticallevel = 17
$criticallevelms = 3500
}
if ( $vcpu -eq 1 ) # warning 1000ms critical 1500ms
{
$warnlevel = 5
$warnlevelms = 1000
$criticallevelms = 1500
}
$statcpureadyper = (($statcpuready) / (20*1000))*100
#Write-Host $statcpureadyper
if ($statcpureadyper -gt $criticallevel) {
Write-Host "CRITICAL:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPUReadySummation(Avg5mins)(ms)="$statcpuready";"$warnlevelms";"$criticallevelms
exit(2)
} elseif ($statcpureadyper -gt $warnlevel) {
Write-Host "WARNING:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPUReadySummation(Avg5mins)(ms)="$statcpuready";"$warnlevelms";"$criticallevelms
exit(1)
} elseif ($statcpureadyper -lt $warnlevel) {
Write-Host "OK:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPUReadySummation(Avg5mins)(ms)="$statcpuready";"$warnlevelms";"$criticallevelms
#Write-Host "OK:CPU Ready (Avg 5mins)%="$statcpureadyper"|CPU Ready (Avg 5mins)%="$statcpureadyper"%;"$warnlevel";"$criticallevel";0;100;CPU Ready Summation in (ms)(Avg 5mins)="$statcpuready";0;0"
exit(0)
}
disconnect-viserver -confirm:$false