# end2end-restransmit # # Reading the TCP Retransmits # # https://www.msxfaq.de/code/powershell/psperfcounter.htm # # 20190702 Initial Version # Pending # International Language # # param ( [string]$csvfilename = "$PWD\end2end-retrantmit_$($env:COMPUTERNAME).csv", # Path to CSV File. Clear to disable CSV [byte]$samplecount=60, [long]$sampleinterval = 1, [switch]$sendtopipeline = $false ) set-psdebug -strict Write-Host "end2end-retransmit: Start" Write-Host " Param CSVFile : $($csvfilename)" Write-Host " Param samplecount : $($samplecount)" Write-Host " Param sampleinterval: $($sampleinterval)" $host.ui.RawUI.WindowTitle = "end2end-retransmit on $($env:COMPUTERNAME)" if ($csvfilename -ne "") { Write-Host "Initialize CSV-File"$csvfilename if (!(test-path $csvfilename -pathtype leaf)){ Write-Host "Adding CSV-Header" "Timestamp,Min,Avg,Max,Total" | out-file $csvfilename -append } } Write-Host "Description: 0= Noretransmits, 2= 1-2 retransmits, 5 = 3-5 retransmits 9= 6-9 retransmit X=11+ Restransmit" while ($true) { $result = [pscustomobject][ordered]@{ timestamp = ((get-date).ToUniversalTime().tostring("u")) min = [long]9999999 avg = [long]0 max = [long]0 total = [long]0 } [long]$Avgsum = 0 Get-Counter ` -Counter "\TCPv4\erneut übertragene Segmente/s" ` -SampleInterval $sampleinterval ` -MaxSamples $samplecount ` | ForEach-Object { $result.total++ $value = [math]::Round($_.countersamples[0].cookedvalue) #write-host "Value: $($value)" switch ($value) { {$_ -le 1} {Write-Host "0" -nonewline -backgroundcolor blue;break;} {$_ -le 2} {Write-Host "2" -nonewline -backgroundcolor green -foregroundcolor black;break;} {$_ -le 5} {Write-Host "5" -nonewline -backgroundcolor yellow -foregroundcolor black;break;} {$_ -le 10} {Write-Host "9" -nonewline -backgroundcolor magenta;break;} default {Write-Host "X" -nonewline -backgroundcolor red} } if ($value -le $result.min) {$result.min = $value} if ($value -ge $result.max) {$result.max = $value} $avgsum+=$value } $Result.avg = [math]::Round($avgsum/$result.total) Write-Host " $($result.timestamp) Min/Avg/Max/Total: $($Result.min)/$($Result.avg)/$($Result.max)/$($Result.total)" if ($csvfilename -ne "") { "$($result.timestamp),$($result.min),$($result.avg),$($result.max),$($result.total)" | out-file $csvfilename -append } if ($sendtopipeline) { Write-Host "Sending result to Pipeline" $result } # Wait for next second $waittime = 1000 - (get-date).millisecond if ($waittime -ge 0) { start-sleep -milliseconds $waittime } } Write-Host "end2end-retransmit: End"