hi - i have the following script that works well until i try to get the Average and Maximum stats for each vmnic. The stats are not as i expect - the figures in all vmnics are basically the same. Can anybody assist ? thanks
$ESXHostTmp = @()
write-host " > " $esxImpl
###data extracting
$esx = $esxImpl | Get-View
$ReportRow = "" | Select-Object pNIC , VSwitch , Speed , Duplex , Status , MAC , vmNICStatus , NICAvReceived , NICAvValueReceived , NICMaxReceived , NICMinReceived , NICAvTransmitted , NICMaxTransmitted , NICMinTransmitted
foreach($pnic in $esx.Config.Network.Pnic){
$vSw = $esxImpl | Get-VirtualSwitch | where {$_.Nic -contains $pNic.Device}
$pg = $esxImpl | Get-VirtualPortGroup | where {$_.VirtualSwitchName -eq $vSw.Name}
$order = ($esx.Config.Network.Vswitch | where {$_.Name -eq $vSw.Name}).Spec.Policy.NicTeaming.NicOrder
$row = "" | Select pNIC , VSwitch , Speed , Duplex , Status , MAC , vmNICStatus , NICAvReceived , NICAvValueReceived , NICMaxReceived , NICMinReceived , NICAvTransmitted , NICMaxTransmitted , NICMinTransmitted
$row.pNic = $pnic.Device
$row.vSwitch = $vSw.Name
$row.Speed = $pnic.LinkSpeed.SpeedMb
$row.Duplex = $pnic.LinkSpeed.Duplex
$row.MAC = $pnic.Mac
$row.Status = &{if($pnic.LinkSpeed -ne $null){"up"}else{"down"}}
$row.vmNICStatus = &{if($order.ActiveNic -contains $pnic.Device){"active"}elseif($order.StandByNic -contains $pnic.Device){"standby"}else{"unused"}}
$row.NICAvReceived = (::round($Receivedvalue.average,2))
$Row.NICMaxReceived = (::round($Receivedvalue.maximum,2))
$Row.NICAvTransmitted = (::round($Transmittedvalue.average,2))
$Row.NICMaxTransmitted = (::round($Transmittedvalue.maximum,2))
############
stats #
############
$Receivedvalue = $esximpl | get-stat –stat “net.received.average” -start (get-date).AddDays(-7) -Finish (Get-Date) –maxsamples 10000 | measure-object –average -maximum -minimum –property value
$Transmittedvalue = $esximpl | get-stat –stat “net.transmitted.average” -start (get-date).AddDays(-7) -Finish (Get-Date) –maxsamples 10000 | measure-object –average -maximum -minimum –property value
$ESXHostTmp += $Row
$report = $report + $row
}
#Host Config
$ESXHostTmp | sort-object PNic | ConvertTo-Html -property pNIC , VSwitch , Speed , Duplex , Status , MAC , vmNICStatus , NICAvReceived , NICMaxReceived | Out-File -append $htmlHOSTNics
}
I moved the ConvertTo-Html line inside the host loop, then it works.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Possible cause of the problem:
I'm not sure that I completely understand your script but I think you're getting the network statistics for all nics on the vmhost(every time the same numbers) when calculating the stats for the separate nics.
Possible fix:
Get-Stat returns samples that have _"instance" _property. In your case this field has the following values : ""(blank) for the average statistics for all nics, "0" for the first nic, "1" for the second nic, etc.
You can use the "Instance" filtering parameter in Get-Stat.
Regards,
Nedko Nedev
PowerCLI Development Team
hi - thanks for the tip - you were correct with your assumptions
Are ther enay examples of how to use the Instance Property ? I can tfind much about it
tks
Have a look at my PowerCLI & vSphere statistics – Part 3 – Instances post.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'll try to write a short explanaition:
Sometimes when you call Get-Stat cmdlet for a specific metric, cpu.usage.average for example, you get a number of samples with identical timestamps and different values in "Instance" and "Value" properties.
So if you have 2 cores you will have 3 samples per timestamp:
Instance="" - The sample with the average for the 2 cores
Instance="0" - The sample for the 1st core
Instance="1" - The sample for the 2nd core
If you're requesting network statistics the instances are NICs, if you're requesting storage statistics the instances are HDDs etc.
If you have any other questions don't hesitate to write here.
Regards,
Nedko Nedev
PowerCLI Development Team
well thanks for the advice everyone - but now im even more confused i have a script that gives me the "net.usage.average" per vm so i will use that for my reporting for now. ill have to come back to trying to get info per vmnic when i have more time. thanks again
aha - i found this LucD script that almost gives me what i want .... it lists the vmnic and sent/received stats but lists the info in a csv. What would i change to just be displayed with the Maximum value, per vmnic, for the "Send MBps" and the "Received MBps" ? ANy assistance would be greatly appreciated !!
$esxName = "xxxxxx"
$entity = Get-VMHost -Name $esxName
$metrics = "net.received.average","net.transmitted.average"
Yesterday
$todayMidnight = Get-Date -Hour 0 -Minute 0 -Second 0
$start = $todayMidnight.AddDays(-1).AddSeconds(1)
$finish = $todayMidnight
$stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish | measure-object –average -maximum -minimum –property value
$stats | Group-Object -Property Instance | where {$_.Name -ne ""} | %{
$_.Group | Group-Object -Property value | %{
$row = "" | Select "ESX Name",Time,NIC,"Send MBps","Received MBps"
$row."ESX Name" = $_.Group[0].Entity.Name
$row.Time = $_.Name
$row.NIC = $_.Group[0].Instance
$row."Send MBps" = "{0:f2}" -f (($_.Group | where {$_.MetricId -eq "net.transmitted.average"}).Value/1KB)
$row."Received MBps" = "" -f (($_.Group | where {$_.MetricId -eq "net.received.average"}).Value/1KB)
$row
}
} | Export-Csv "C:\NIC-Stats.csv" -NoTypeInformation -UseCulture
Remove the pipe to the Export-Csv cmdlet at the end to see the results on screen.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi luc - i get the error "Get-Stat : 08/09/10 3:23:30 PM Get-Stat The metric counter "net.received.maximum" doesn't exist for entity "xxxxxx".
Could it be that the statistics level are not high enough ?
My mistake, there is no maximum metric for net.received.
Over which time period do you want to see the maximum ? Per day ?
Il removed the faulty script
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The following script will give the maximum values per hour for each vnic for the previous day.
$entity = Get-VMHost -Name $esxName $metrics = "net.received.average","net.transmitted.average" # Yesterday $todayMidnight = Get-Date -Hour 0 -Minute 0 -Second 0 $start = $todayMidnight.AddDays(-1).AddSeconds(1) $finish = $todayMidnight $stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish $stats | Group-Object -Property Instance | where {$_.Name -ne ""} | %{ $_.Group | Group-Object -Property {$_.Timestamp.Hour} | %{ $row = "" | Select "ESX Name",Date,Hour,NIC,"Max Send MBps","Max Received MBps" $row."ESX Name" = $_.Group[0].Entity.Name $row.Date = $start.ToShortDateString() $row.Hour = $_.Name $row.NIC = $_.Group[0].Instance $row."Max Send MBps" = "{0:f2}" -f (($_.Group | where {$_.MetricId -eq "net.transmitted.average"} | Measure-Object -Property Value -Maximum).Maximum/1KB) $row."Max Received MBps" = "{0:f2}" -f (($_.Group | where {$_.MetricId -eq "net.received.average"} | Measure-Object -Property Value -Maximum).Maximum/1KB) $row } }
Note that the period for which you want the report is important.
If you go back further in time the values returned go over longer intervals than 1 hour.
See my PowerCLI & vSphere statistics – Part 1 – The basics post for an introduction on the Historical Intervals and how aggregation works.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi luc - thats great - im nearly there now. If i wanted to only display the maximum value for received/transmitted in he previous 24 hours (not the value per hour) - how would this be achieved ? so the report would look something like ...
vmnic0 maxrecd maxtransmit
vmnic1 maxrecd maxtransmit
vmnic2 etc etc
thanks for your help so far
regards
We just have to leave out the grouping per hour.
Something like this
$entity = Get-VMHost -Name $esxName $metrics = "net.received.average","net.transmitted.average" # Yesterday $todayMidnight = Get-Date -Hour 0 -Minute 0 -Second 0 $start = $todayMidnight.AddDays(-1).AddSeconds(1) $finish = $todayMidnight $stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish $stats | Group-Object -Property Instance | where {$_.Name -ne ""} | %{ $row = "" | Select "ESX Name",Date,NIC,"Max Send MBps","Max Received MBps" $row."ESX Name" = $_.Group[0].Entity.Name $row.Date = $start.ToShortDateString() $row.NIC = $_.Group[0].Instance $row."Max Send MBps" = "{0:f2}" -f (($_.Group | where {$_.MetricId -eq "net.transmitted.average"} | Measure-Object -Property Value -Maximum).Maximum/1KB) $row."Max Received MBps" = "{0:f2}" -f (($_.Group | where {$_.MetricId -eq "net.received.average"} | Measure-Object -Property Value -Maximum).Maximum/1KB) $row } | ft -AutoSize
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I moved the ConvertTo-Html line inside the host loop, then it works.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi luc
thats great - thanks for the info - ithink i must have tried something very similar - still - i learn someething new every day