VMware Cloud Community
Gaprofitt17
Enthusiast
Enthusiast

Host network utlization report

Hey All,

I need some help, I am trying to figure out how to accomplish something.  Here is the scenario..

I have 4 10GB interfaces for each host (say vmnic0-4).  I am trying to get network.usage.avg, min and max for all hosts for say the last 30 days.  I am looking for a percentage of total bandwidth calculation for each interface, not Kbps.

How would I script this out and are certain stat interval levels required? If they are we can skip the min and max.

Thanks so much.

0 Kudos
1 Reply
LucD
Leadership
Leadership

Network.usage min and max requires statistics level 4, and since you want to go back 30 days, that would mean for Historical Interval 3.

The other limitation is that if you want to have a number per vnic you would also need Statistics Level 3.

Try something like this

$stat = 'net.usage.average'

$start = (Get-Date).AddDays(-30)

$esx = Get-VMHost

Get-Stat -Entity $esx -Start $start -Stat $stat |

Group-Object -Property {$_.Entity.Name} |

Select @{N='ESX';E={$_.Name}},

    @{N='NetAvg%';E={

        $average = $_.Group | where{$_.Instance -eq ''} |

            Measure-Object -Property Value -Average | Select -ExpandProperty Average

        $pnicInUse = @()

        $pnicInUse += ($_.Group[0].Entity.ExtensionData.Config.Network.ProxySwitch | %{

          $_.Pnic

        })

        $pnicInUse += ($_.Group[0].Entity.ExtensionData.Config.Network.Vswitch | %{

          $_.Pnic

        })

        $bitRateSec = $_.Group[0].Entity.ExtensionData.Config.Network.Pnic |

          where{$pnicInUse -contains $_.Key} | %{$_.LinkSpeed.SpeedMb} |

          Measure-Object -Sum | Select -ExpandProperty Sum

        "{0:p4}" -f ($average/($BitRateSec * 8KB))

    }}

The script will determine for each ESXi nodes that active pNICs, and calculate the cumulative network speed (in Mbps).

From the statistics it gets the average network usage for the ESXi node (in KBps).

Then it is a matter of converting and expressing as a percentage.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos