VMware Cloud Community
AlbertWT
Virtuoso
Virtuoso
Jump to solution

How to get statistics of all VMs that is dropping the network packet in the past week ?

Hi,

I've got this script (again) thanks to Mr. LucD which "supposed to" gather the list of statistic of any network packet dropped within the specified time frame:$start = Get-Date "1/01/2015 00:00"

$finish = Get-Date "21/01/2015 14:30"

$metrics = "net.droppedRx.summation","net.droppedTx.summation"

foreach($esx in (Get-VMHost)){

    $vms = Get-VM -Location $esx

    if($vms){

        Get-Stat -Entity $vms -Stat $metrics -Start $start -Finish $finish -ErrorAction SilentlyContinue |

        where {$_.Instance -ne ""} |

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

            $_.Group | Group-Object -Property Timestamp | %{

                New-Object PSObject -Property @{

                    VMHost = $esx.Name

                    VM = $_.Group[0].Entity.Name

                    VmNic = $_.Group[0].Instance

                    "Receive Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedRx.summation"} | Select -ExpandProperty Value

                    "Transmit Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedTx.summation"} | Select -ExpandProperty Value

                    Timestamp = $_.Group[0].Timestamp

                    "Interval (seconds)" = $_.Group[0].IntervalSecs

                }

            }

        }

    }

} | Export-CSV -path C:\Temp\Result.CSV

but somehow there is no result coming out from that script?

How can I get the result in the .CSV file ?

/* Please feel free to provide any comments or input you may have. */
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The ForEach doesn't place anything in the pipeline, but that can be fixed by using the call operator (&)

$finish = Get-Date "21/01/2015 14:30" 

$metrics = "net.droppedRx.summation","net.droppedTx.summation" 

&{foreach($esx in (Get-VMHost)){ 

    $vms = Get-VM -Location $esx 

    if($vms){ 

        Get-Stat -Entity $vms -Stat $metrics -Start $start -Finish $finish -ErrorAction SilentlyContinue | 

        where {$_.Instance -ne ""} | 

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

            $_.Group | Group-Object -Property Timestamp | %

                New-Object PSObject -Property @{ 

                    VMHost = $esx.Name 

                    VM = $_.Group[0].Entity.Name 

                    VmNic = $_.Group[0].Instance 

                    "Receive Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedRx.summation"} | Select -ExpandProperty Value 

                    "Transmit Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedTx.summation"} | Select -ExpandProperty Value 

                    Timestamp = $_.Group[0].Timestamp 

                    "Interval (seconds)" = $_.Group[0].IntervalSecs 

                } 

            } 

        } 

    } 

}} | Export-CSV -path C:\Temp\Result.CSV  


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

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

The ForEach doesn't place anything in the pipeline, but that can be fixed by using the call operator (&)

$finish = Get-Date "21/01/2015 14:30" 

$metrics = "net.droppedRx.summation","net.droppedTx.summation" 

&{foreach($esx in (Get-VMHost)){ 

    $vms = Get-VM -Location $esx 

    if($vms){ 

        Get-Stat -Entity $vms -Stat $metrics -Start $start -Finish $finish -ErrorAction SilentlyContinue | 

        where {$_.Instance -ne ""} | 

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

            $_.Group | Group-Object -Property Timestamp | %

                New-Object PSObject -Property @{ 

                    VMHost = $esx.Name 

                    VM = $_.Group[0].Entity.Name 

                    VmNic = $_.Group[0].Instance 

                    "Receive Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedRx.summation"} | Select -ExpandProperty Value 

                    "Transmit Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedTx.summation"} | Select -ExpandProperty Value 

                    Timestamp = $_.Group[0].Timestamp 

                    "Interval (seconds)" = $_.Group[0].IntervalSecs 

                } 

            } 

        } 

    } 

}} | Export-CSV -path C:\Temp\Result.CSV  


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

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Luc,

Somehow the script doesn't work when I executed to get the statistics in the past one week as per below:

$start = Get-Date "15/01/2015 00:00"

$finish = Get-Date "22/01/2015 17:30"

$metrics = "net.droppedRx.summation","net.droppedTx.summation"

&{foreach($esx in (Get-VMHost)){

    $vms = Get-VM -Name DCTS802 -Location $esx

    if($vms){

        Get-Stat -Entity $vms -Stat $metrics -Start $start -Finish $finish -ErrorAction SilentlyContinue |

        where {$_.Instance -ne ""} |

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

            $_.Group | Group-Object -Property Timestamp | %{

                New-Object PSObject -Property @{

                    VMHost = $esx.Name

                    VM = $_.Group[0].Entity.Name

                    VmNic = $_.Group[0].Instance

                    "Receive Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedRx.summation"} | Select -ExpandProperty Value

                    "Transmit Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedTx.summation"} | Select -ExpandProperty Value

                    Timestamp = $_.Group[0].Timestamp

                    "Interval (seconds)" = $_.Group[0].IntervalSecs

                }

            }

        }

    }

}} | Export-CSV -path C:\Temp\Result.CSV -NoTypeInformation -UseCulture

There is no result, the .CSV file is empty.

but when I execute the following one liner:

Get-Stat -Entity (Get-VMHost PRODESXi56.domain.com ) -Stat "net.packetsRx.summation","net.droppedRx.summation","net.packetsTx.summation" -Start (Get-Date).AddMinutes(-60) | Group-Object -Property MetricId,Instance | ft -AutoSize

I can see the result:

Count Name                            Group                          

----- ----                            -----                          

  180 net.packetsrx.summation,        {85256, 58639, 64257, 109083...}

  180 net.packetstx.summation,        {23433, 22353, 21904, 23208...}

  180 net.packetsrx.summation, vmnic6 {1, 1, 2, 1...}                

  180 net.packetsrx.summation, vmnic7 {2, 0, 2, 2...}                

  180 net.packetsrx.summation, vmnic4 {45971, 37794, 41318, 59452...}

  180 net.packetsrx.summation, vmnic5 {38677, 19188, 22766, 49367...}

  180 net.packetsrx.summation, vmnic2 {5, 5, 6, 5...}                

  180 net.packetsrx.summation, vmnic3 {6, 4, 6, 6...}                

  180 net.packetsrx.summation, vmnic0 {84, 8, 65, 11...}             

  180 net.packetsrx.summation, vmnic1 {510, 1639, 92, 239...}        

  180 net.droppedrx.summation, vmnic0 {0, 0, 0, 0...}                

  180 net.droppedrx.summation, vmnic2 {0, 0, 0, 0...}                

  180 net.droppedrx.summation, vmnic1 {0, 0, 0, 0...}                

  180 net.droppedrx.summation, vmnic4 {0, 0, 0, 0...}                

  180 net.droppedrx.summation, vmnic3 {0, 0, 0, 0...}                

  180 net.droppedrx.summation, vmnic6 {0, 0, 0, 0...}                

  180 net.droppedrx.summation, vmnic5 {0, 0, 0, 0...}                

  180 net.droppedrx.summation, vmnic7 {0, 0, 0, 0...}                

  180 net.packetstx.summation, vmnic1 {330, 405, 52, 144...}         

  180 net.packetstx.summation, vmnic0 {79, 3, 45, 5...}              

  180 net.packetstx.summation, vmnic3 {0, 0, 0, 0...}                

  180 net.packetstx.summation, vmnic2 {0, 0, 0, 0...}                

  180 net.packetstx.summation, vmnic5 {3241, 1215, 1249, 2718...}    

  180 net.packetstx.summation, vmnic4 {19783, 20730, 20558, 20341...}

  180 net.packetstx.summation, vmnic7 {0, 0, 0, 0...}                

  180 net.packetstx.summation, vmnic6 {0, 0, 0, 0...}                

  180 net.droppedrx.summation,        {0, 0, 0, 0...}                

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There are a few things to check from your side:

  • Do you also get data returned when you specify the same Start and Finish ? The script and the command are interrogating 2 different Historical Intervals
  • These metrics require at least Statistics Level 2, is that configured for the time interval you are looking at ?
  • Do you see data under the Performance tab for that VM for the Last Week ?


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

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Ah I see,

Here's my settings:Stat.JPG

is that the cause why I cannot ge the past week data ?

So if I change it into level 2 today, can I still get the statistics or not really because it is point forward ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that looks to be the issue.

You could check by running that command you used, but then with the same Start and Finish as used in the script.

Or look under the Performance tab in the vSphere client.

And yes, changing the level means "from this point in time onwards".

So you will have to wait at least 1 week, before you can see the result I'm afraid.


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

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Yes, it works Luc, when I changed the timeframe to be less than 24 hours.

However, is it possible to group the result by VM so that it returns the total number of dropped packets rather than per incident per VM ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos