Hi All
Am using below script to capture CPU and Mem report for Last 2 weeks since last month there was no issues and am getting the report correctly but now am not getting the CPU value correctly
Only change what i have done is Updated the host from ESXi 5.5 U2 to Esxi 5.5 U3d
# VCenter Server Details
$server_address = "Vcenter1"
add-pssnapin vmware.vimautomation.core
Connect-VIserver -server $server_address
Write-host "Gathering Avg CPU & MEM utilization of ESX hosts for last 2 weeks"
$d = get-date -DisplayHint DateTime -Format "d-MMM-yy"
$host1 = Get-vmhost | sort
$utilization = @()
$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)
$workingDays = "Monday","Tuesday","Wednesday","Thursday","Friday"
$dayStart = New-Object DateTime(10,04,17,0,00,0) # 00:00 AM
$dayEnd = New-Object DateTime(23,04,17,23,59,0) # 12:50 PM
Foreach ( $h in $host1)
{
$ESXhost = $h.name
# Calculate the Average CPU Usage of each ESX host
$A = Get-Stat -entity $h.name -stat cpu.usage.average -start (get-Date).adddays(-15) -finish (get-date).adddays(-1)
$report = $A | Where-Object {
$workingDays -contains $_.Timestamp.DayOfWeek -and
$_.Timestamp.TimeOfDay -ge $dayStart.TimeOfDay -and
$_.Timestamp.TimeOfDay -le $dayEnd.TimeOfDay }
$CPU1 = $report | Measure-Object -property value -average
$CPU1 = $CPU1.Average
# Calculate the Average MEM Usage of each ESX host
$B = Get-Stat -entity $h.name -stat mem.usage.average -start (get-Date).adddays(-15) -finish (get-date).adddays(-1)
$report1 = $B | Where-Object {
$workingDays -contains $_.Timestamp.DayOfWeek -and
$_.Timestamp.TimeOfDay -ge $dayStart.TimeOfDay -and
$_.Timestamp.TimeOfDay -le $dayEnd.TimeOfDay }
$MEM1 = $report1 | Measure-Object -property value -average
$MEM1 = $MEM1.Average
# Create a new object for output
$objHostInfo = New-Object System.Object
$objHostInfo | Add-Member -MemberType NoteProperty -Name AvgCPU -Value $CPU1
$objHostInfo | Add-Member -MemberType NoteProperty -Name AvgMEM -Value $MEM1
$objHostInfo | Add-Member -MemberType NoteProperty -Name HostIP -Value $ESXhost
$utilization += $objHostInfo
}
$utilization | Export-csv C:\Report-$d.csv
Do you have some more info on how the report is incorrect?
Perhaps show the results next to a screenshot of the Performance Advanced tab.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Cpu values are coming in single digit and previously it was in double digit and ranges from AVG of 40 to 50 %
AvgCPU | AvgMEM | ESX Host |
1.20014 | 95.32108 | host1 |
0.356528 | 51.42383 | host2 |
1.388429 | 84.77133 | host3 |
1.636207 | 84.71558 | host4 |
2.497207 | 53.55142 | host5 |
1.053056 | 91.16175 | host6 |
1.235409 | 87.18933 | host7 |
1.429672 | 81.40492 | host8 |
1.930977 | 91.2515 | host9 |
2.513631 | 90.65842 | host10 |
1.641263 | 56.26758 | host11 |
1.921866 | 75.768 | host12 |
2.128366 | 63.44075 | host13 |
1.969909 | 83.055 | host14 |
1.410768 | 84.01692 | host15 |
1.592169 | 87.81858 | host16 |
0.045986 | 3.71 | host17 |
1.587299 | 94.7795 | host18 |
1.725955 | 84.86358 | host19 |
2.775827 | 72.46992 | host20 |
2.150527 | 69.31542 | host21 |
2.15692 | 77.13483 | host22 |
Try adding -Instance '' on the Get-Stat cmdlet.
if you have multi-core CPU's on the ESXi nodes, you will get incorrect results.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference