hakhak
Contributor
Contributor

How to get a total network transmit and receive in 7 days?

Hi, I wonder is there any idea or script that would be able to get a total VM network transmit and receive in 7 days instead of average?

0 Kudos
3 Replies
LucD
Leadership
Leadership

Afaik, there is no direct metric that gives you those numbers over the last 7 days (Historical Interval 2).

Also remember that the metrics are aggregated for the Historical Intervals.

See my PowerCLI & vSphere statistics – Part 1 – The basics post for more details on this.

If you ask for metric values over the last 7 days, you could use the net.bytesRx.average and net.bytesTx.average.

This will give you the average number of bytes transmitted and received during the interval.

If you multiply the average number of bytes (KBps) by the number of seconds in the interval you should get a decent approximation of the absolute values you are after.

Something like this

Get-VM |
Get-Stat -Stat "net.bytesRx.average","net.bytesTx.average" -Start (Get-Date).AddDays(-7) |
Group-Object -Property {$_.Entity.Name} |
Select @{N="VM";E={$_.Name}},
    @{N="Received (KB)";E={
        ($_.Group | where {$_.MetricId -eq "net.bytesRx.average"} | %{$_.Value * $_.IntervalSecs} |
        Measure-Object -Sum).Sum}},
    @{N="Transmitted (KB)";E={
        ($_.Group | where {$_.MetricId -eq "net.bytesTx.average"} | %{$_.Value * $_.IntervalSecs} |
        Measure-Object -Sum).Sum}}

Note that this script will summarise traffic for all vNICs that a VM has.

The script also requires at least statistics level 2 for Historical Interval 2.


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

hakhak
Contributor
Contributor

hi LucD,

alright, thanks for the script. By the way, I have another question, how about virtual disk? how can i get total write and read in 7 days? I can only get the average instead of total. Apperciate that you may help on this.

0 Kudos
LucD
Leadership
Leadership

You could use the same concept, but with the virtualdisk.read.average and virtualdisk.write.average metrics.

Get-VM |
Get-Stat -Stat "virtualdisk.read.average","virtualdisk.write.average" -Start (Get-Date).AddDays(-7) |
Group-Object -Property {$_.Entity.Name} |
Select @{N="VM";E={$_.Name}},
    @{N="Read (KB)";E={
        ($_.Group | where {$_.MetricId -eq "virtualdisk.read.average"} | %{$_.Value * $_.IntervalSecs} |
        Measure-Object -Sum).Sum}},
    @{N="Write (KB)";E={
        ($_.Group | where {$_.MetricId -eq "virtualdisk.write.average"} | %{$_.Value * $_.IntervalSecs} |
        Measure-Object -Sum).Sum}}

The script summarises all the virtual disks per VM.


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

0 Kudos