Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Sec 91236d8 May 20, 2016
1 contributor

Users who have contributed to this file

50 lines (43 sloc) 1.62 KB
# The script will calculate the ESXi host CPU core to VM vCPU oversubscription and create a HTML report
#————————————————
# Start of script parameters section
#
# vCenter Server configuration
$vcenter = “vc01.home.uw.cz“
$vcenteruser = “readonly“
$vcenterpw = “readonly“
$loginsight = "192.168.4.51"
#
# End of script parameter section
#—————————————— #
$o = Add-PSSnapin VMware.VimAutomation.Core
$o = Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
#
# Connect to vCenter Server
$vc = connect-viserver $vcenter -User $vcenteruser -Password $vcenterpw
#
Clear-Host
# Send Message to LogInsight
function Send-LogInsightMessage ([string]$ip, [string]$message)
{
$uri = "http://" + $ip + ":9000/api/v1/messages/ingest/1"
$content_type = "application/json"
$body = '{"messages":[{"text":"'+ $message +' "}]}'
$r = Invoke-RestMethod -Uri $uri -ContentType $content_type -Method Post -Body $body
}
foreach ($esx in (Get-VMHost | Sort-Object Name)) {
$pCPUs = $esx.NumCpu
$vCPUs = ($esx | get-vm | Measure-Object -Sum NumCPU).Sum
$CPU_ratio = $vCPUs / $pCPUs
$date = (Get-Date).ToUniversalTime()
$cluster_name = get-cluster -VMHost $esx
$message = "UTC date time: $date Cluster: $cluster_name ESX name: $esx.Name pCPUs: $pCPUs vCPUs: $vCPUs vCPU/pCPU ratio: $CPU_ratio"
Write-Host $message -Foreground Green
Try {
Send-LogInsightMessage $loginsight $message
} Catch {
Write-Host "Cannot connect to LogInsight. Breaking the script." -ForegroundColor Red
Break
}
}
disconnect-viserver -Server $vc -Force -Confirm:$false
You can’t perform that action at this time.