While these tools provide latency from one source point to another, you may find that you need to run tests from multiple points. Connections can get complicated with multiple layers and applications that give you a full end to end experience through multiple servers and protocols. In these cases, you will need to work through to determine what your various points in the connection are, and at what points you need to test from. For example, you may be doing remote desktop through a jump server (bastion host). Your workstation doesn't have direct access to the final remote desktop server. Testing connectivity from the jump server to the final destination only gives you part of the total round trip end to end connectivity. You will need to test from the workstation to the jump server, and then add the latency of the jump server to the final destination to get a rough idea of your end to end latency. If you can run ping's at the different layers, it will help give an idea of packet loss as well.
function Test-PortLatency { param ( [parameter(mandatory=$true)][string]$Computer, [parameter(mandatory=$true)][int]$Port, [parameter(helpmessage="Timeout in milliseconds")]$timeout=10000 ) $starttime = get-date $Testconn = New-Object Net.Sockets.TcpClient $Testconn.BeginConnect( $computer, $Port, $Null, $Null ) | Out-Null $MaxTimeout = ( Get-Date ).AddMilliseconds( $timeout) $millisec = 0 While ( -not $Testconn.Connected -and ( Get-Date ) -lt $maxTimeout ) { Sleep -Milliseconds 10 $ms += 10 } $endtime = get-date $result = new-object psobject add-member -input $result NoteProperty Connected $($testconn.connected) add-member -input $result NoteProperty Milliseconds $(($endtime - $starttime).totalmilliseconds) if ($testconn.client.remoteendpoint -eq $null) { $resultstr = "Connection_Refused" } elseif ($result.milliseconds -gt $timeout) { $resultstr = "Connection_TimedOut" } elseif ($result.connected) { $resultstr = "Successful_connection" } else { $resultstr = "status_unknown" } add-member -input $result NoteProperty Result $resultstr $Testconn.Close() $result }
No comments:
Post a Comment