Wednesday, September 10, 2014

Capture ping Latency or drops results with powershell - Part1


Powershell Ping multiple IP addresses
Capture ping Latency or drops results with powershell - Part1
Capture multiple IP Latency or drops results with powershell Test-Connection - Part 2
Schedule PowerShell (.PS1 file) script in Windows Task Scheduler - Part 3
 
Many times users reported me that they are facing slowness and lagging on the terminal servers, after analysis I didn't find any issue with CPU or Memory but sometimes Network slowness. Network is fluctuating and latency in MS has been increased. (This help when opening case with ISP vendor or contacting network team.)

To know at what time this is happening I use this script to capture the time when Latency increased above the bench-marked one. It will also store if drops has been increased.

Once you run this script, it will ask for IPaddress or ComputerName. On the second line When should it captures the ping results (if latency increases equal or more than 80, it will keep storing data in CSV file). And on the final line the path for csv file to store data.

In this Powershell script i have used Ping tool to capture in my next post I will capture same data using other Powershell command.
 ######################################################################  
 $computername = Read-Host "Ipaddress or Computername"  
 $LatencytoMonitor = Read-Host "Latency to monitor"  
 #$filename = "C:\temp\PingResult-$computername.csv"  
 $filename = Read-Host "Type path ie C:\temp\ComputerNamePingResult.csv"  
 ######################################################################  
 $x = $true  
 do  
 {  
   $Ping = Ping -n 1 $computername | Select-String -Pattern "Request", "Reply from"  
   $Pingstatus = $Ping[0]  
   $IP = $($Pingstatus -split("reply from ") -split (":"))[1]  
   if ($Pingstatus -match "Request timed out") {  
     #$Pingstatus  
     $TestResult = "" | Select-Object IPAddress, Latencyms, DateTime  
     $TestResult.IpAddress = $computername  
     $TestResult.Latencyms = "NotReachable"  
     $TestResult.DateTime = Get-Date  
     $TestResult | Export-Csv -Path $filename -Append -NoTypeInformation  
   }    
   elseif ($PingStatus -match "Reply from $IP") {  
     if (-not (Get-Variable Latencyms)) {  
       Remove-Variable -Name Latencyms -Force  
     }  
     $Latencyms = $Pingstatus -split ("time")  
     $Latencyms = $Latencyms[1].Substring(1)  
     $Latencyms = $Latencyms.Split("ms")[0]  
     if ([Int]$Latencyms -ge $LatencytoMonitor) {  
       #$Pingstatus  
       $TestResult = "" | Select-Object IPAddress, Latencyms, DateTime  
       $TestResult.IPAddress = $computername  
       $TestResult.Latencyms = $Latencyms  
       $TestResult.DateTime = Get-Date  
       $TestResult | Export-Csv -Path $filename -Append -NoTypeInformation  
     }  
       <#else {  
         "DO nothing"  
       }#>  
   }  
   else {  
     #$Pingstatus  
     $TestResult = "" | Select-Object IPAddress, Latencyms, DateTime  
     $TestResult.IPAddress = $computername  
     $TestResult.Latencyms = "GenericFailure"  
     $TestResult.DateTime = Get-Date  
     $TestResult | Export-Csv -Path $filename -Append -NoTypeInformation  
   }  
 }  
 while ($x -eq $true)  
 ###############################################################################  
 #Please test it at your own risk.  
 http://kunaludapi.blogspot.com   
 Keywords: capture ping request timed out and high latency

1 comment:

LifeVoxel.AI said...

LifeVoxel.AI has developed a Interactive Streaming and AI Platform for medical imaging using GPU clusters cloud computing. It is a leap in cloud technology platform in medical imaging that encompasses use cases in visualization, AI, image management and workflow. It’s approach is unique that it has been granted 12 International patents. LifeVoxel.AI’s platform is certified for HIPAA compliancy. LifeVoxel’s cloud addresses the Internet limitations of bandwidth, latency and scalability which are pivotal in this respect. The platform was granted an FDA 510K approval for use in diagnostic interpretation of medical images.

LifeVoxel.AI Interactive Streaming AI Platform RIS PACS server Medical Imaging