VMware Cloud Community
lElOUCHE_79
Enthusiast
Enthusiast
Jump to solution

Test vmkping within a cluster

due to a random issue we need to check the vmkping for the entire cluster.

I found the below script on the internet, and I would like to know if it's possible to reconfigure it to test ping on all interfaces and collect report

 

$esxcli = Get-EsxCli -VMHost (Get-VMHost "testesxihost") -V2

$params = $esxcli.network.diag.ping.CreateArgs()

$params.host = '10.1.1.2'

$params.interface = 'vmk0'

$params.size = '1472' #use 1472 for 1500 MTU or 8972 for 9000 MTU (VMware uses these values on MTU pings on ESXi)

$res = $esxcli.network.diag.ping.Invoke($params) $res.summary

Labels (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can just pipe the result to Export-Csv.
No, my Received value shows the number of packets that were received back.
If there is an issue with the interface than you could see values different from 0.
The RoundTripAvg is time in 10-6 x seconds, or 10-3 x milliseconds.

$myIP = (Get-NetIPConfiguration).IPv4Address.IPAddress

$sPing = @{
    host      = $myIP
    interface = ''
    size      = '1472'
}
$clusterName = 'cluster'

Get-Cluster -Name $clusterName |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $esxcli = Get-EsxCli -VMHost $esx -V2
        $esxcli.network.ip.interface.list.Invoke() |
            ForEach-Object -Process {
                $sPing.interface = $_.Name
                $esxcli.network.diag.ping.Invoke($sPing) |
                    select @{N = 'Cluster'; E = { $clusterName } },
                    @{N = 'VMHost'; E = { $esx.Name } },
                    @{N = 'VMKernel'; E = { $sPing.interface } },
                    @{N = 'Target'; E = { $_.Summary.HostAddr } },
                    @{N = 'Transmitted'; E = { $_.Summary.Transmitted } },
                    @{N = 'Received'; E = { $_.Summary.Received } },
                    @{N = 'Lost'; E = { $_.Summary.PacketLost } },
                    @{N = 'RoundtripAvg'; E = { $_.Summary.RoundtripAvg } }
                }
            } |
Export-Csv -path .\report.csv -NotypeInformation -UseCulture


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this.
I use the IP address of the my station, but you can change that to any IP address you want.

 

$myIP = (Get-NetIPConfiguration).IPv4Address.IPAddress

$sPing = @{
    host      = $myIP
    interface = ''
    size      = '1472'
}
$clusterName = 'cluster'

Get-Cluster -Name $clusterName |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $esxcli = Get-EsxCli -VMHost $esx -V2
        $esxcli.network.ip.interface.list.Invoke() |
            ForEach-Object -Process {
                $sPing.interface = $_.Name
                $esxcli.network.diag.ping.Invoke($sPing) |
                    select @{N = 'Cluster'; E = { $clusterName } },
                    @{N = 'VMHost'; E = { $esx.Name } },
                    @{N = 'VMKernel'; E = { $sPing.interface } },
                    @{N = 'Target'; E = { $_.Summary.HostAddr } },
                    @{N = 'Transmitted'; E = { $_.Summary.Transmitted } },
                    @{N = 'Received'; E = { $_.Summary.Received } },
                    @{N = 'Lost'; E = { $_.Summary.PacketLost } },
                    @{N = 'RoundtripAvg'; E = { $_.Summary.RoundtripAvg } }
                }
            }

 


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

Reply
0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast
Jump to solution

Thank you LucD 🙂

it's working fine except that it's pinging only vmk2 and not able to get a report.

it's possible to ping all vmkernel or no?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

My bad, I misplaced the closing curly brace for the inner loop.
The code above is corrected.


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

Reply
0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast
Jump to solution

No issue LucD, now it's much better 🙂 

it's pinging all interfaces which is perfect, unfortunately I tried in multiple way to have the output in csv without success 😞

also I would like to know

the received argement is empty, is that OK?

the number that I fing in lost it's in percentage?

The RoundtripAvg it's the MTU Size?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can just pipe the result to Export-Csv.
No, my Received value shows the number of packets that were received back.
If there is an issue with the interface than you could see values different from 0.
The RoundTripAvg is time in 10-6 x seconds, or 10-3 x milliseconds.

$myIP = (Get-NetIPConfiguration).IPv4Address.IPAddress

$sPing = @{
    host      = $myIP
    interface = ''
    size      = '1472'
}
$clusterName = 'cluster'

Get-Cluster -Name $clusterName |
    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $esxcli = Get-EsxCli -VMHost $esx -V2
        $esxcli.network.ip.interface.list.Invoke() |
            ForEach-Object -Process {
                $sPing.interface = $_.Name
                $esxcli.network.diag.ping.Invoke($sPing) |
                    select @{N = 'Cluster'; E = { $clusterName } },
                    @{N = 'VMHost'; E = { $esx.Name } },
                    @{N = 'VMKernel'; E = { $sPing.interface } },
                    @{N = 'Target'; E = { $_.Summary.HostAddr } },
                    @{N = 'Transmitted'; E = { $_.Summary.Transmitted } },
                    @{N = 'Received'; E = { $_.Summary.Received } },
                    @{N = 'Lost'; E = { $_.Summary.PacketLost } },
                    @{N = 'RoundtripAvg'; E = { $_.Summary.RoundtripAvg } }
                }
            } |
Export-Csv -path .\report.csv -NotypeInformation -UseCulture


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

Reply
0 Kudos
lElOUCHE_79
Enthusiast
Enthusiast
Jump to solution

then for sure there's something wrong in our network as the received packet is empty 🙂 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then you probably forgot the pipeline symbol (|) on the the second to last line


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

Reply
0 Kudos
mike2652493
Contributor
Contributor
Jump to solution

Is there a way of incorporating the line below into a loop, so the script looks up all vsan IP's - Filters on vmk2 (for us) on the defaulttcpipstack and reports back all ping tests from each host

$esxcli.vsan.cluster.unicastagent.list.invoke() | select 'IPAddress'

So the output would be from a 4 node cluster, each host would ping the other three nodes based on the unicast address and formatted in a table so we could highlight if one host was having an issue.

The original idea came from a VMware engineer who ran the below script locally via SSH on all hosts in a cluster to identify intermittent packet drops that vsan and vrops didn't pick up on.

for i in `localcli vsan cluster unicastagent list | grep true | awk '{ print $4}'`; do echo "pinging $i 3 times"; echo; vmkping -I vmk2 $i -s 8972 -d -c 500 -i .005 ; echo; echo "**************************"; done | grep -C 1 packet

many thanks

Reply
0 Kudos
fannol
Enthusiast
Enthusiast
Jump to solution

It is better to open a new thread as it is easier for the others to find the script.

You can use the following script. If you need more parameters to be passed to the vmkping, feel free to add it.

 

 

 

$vCenter = "<vCenter>"
$ClusterName = "<clusterName>"

Connect-VIServer -Server $vCenter

$VMhosts = Get-Cluster $ClusterName | Get-VMHost | Select *, @{n = 'vSANvmkernel'; e = { ($_ | Get-VMHostNetworkAdapter -VMKernel | Where VsanTrafficEnabled).Name } }

$vmkpingResult = @()
foreach ($VMHost in $VMhosts) {

    $ESXcli = Get-EsxCli -V2 -VMHost $VMHost.Name
    $UnicastInfo = $ESXcli.vsan.cluster.unicastagent.list.Invoke() | Where SupportsUnicast -eq $true
    foreach ($Unicast in $UnicastInfo) {
        $Arguments = $ESXcli.network.diag.ping.CreateArgs()

        $Arguments.host = $Unicast.IPAddress
        $Arguments.interface = $VMHost.vSANvmkernel
        $Arguments.size = 8972
       
        $Result = $esxcli.network.diag.ping.Invoke($Arguments)

        $props = [ordered]@{}
        $props.'VMHost' = $VMHost.Name
        $props.'PingAddress' = $Result.Summary.HostAddr
        $props.'Transmitted' = $Result.Summary.Transmitted
        $props.'PacketLost' = $Result.Summary.PacketLost

        $vmkpingResult += [pscustomobject]$props
    }
}

return $vmkpingResult

 

 

 

Blog: PowerCli.net
Reply
0 Kudos
mike2652493
Contributor
Contributor
Jump to solution

Amazing thankyou.

Reply
0 Kudos