Saturday, September 13, 2014

Capture multiple IP Latency or drops results with powershell Test-Connection - Part 2


Capture ping Latency or drops results with powershell - Part1 

In my earlier blog I used ping tool to capture Latency and Request time out details in CSV file. Here I have used native powershell Test-Connection cmdlet. One of the flexibility I am getting with Test-connection is ping Multiple IP or Computername.

How you can run this script?
I generally use Powershell ISE for writing script, launch it from start menu.


You might end up with error if it is blocked to run scripts (This is by default behavior). You can check the status using Get-ExecutionPolicy cmdlet. And modify policy to run script using Set-ExecutionPolicy cmdlet (Make sure you have opened powershell Run as administrator).


It ask for confirmation of registry entries.

 


Once the Green play button or F5 key pressed script will run and it will get loaded in the memor.

Now to execute type and press enter, make the necessary changes as per your requirement.
Ping-Latency -ComputerName 255.255.255.255, MyRemote, 192.168.33.40 -Latency 100 -Hours 1 -File c:\temp\CapturedData.csv

Ping-Latency: is cmdlet
-Computername: Mention more than 1 IP address (255.255.255.255, MyRemote, 192.168.33.40)
-Latency: Above what latency you want to capture data.
-Hours: For how many hours you want to run the cmdlet.
-File: CSV file location


Once it completed check the CSV file.

You can also just check typing Ping-Latency and press enter.

 
 #####################################  
 ## http://kunaludapi.blogspot.com  
 ## Version: 1  
 ## Tested this script on  
 ##  1) Powershell v3  
 ##  2) Windows 7
 ##
 #####################################  
function Ping-Latency {  
   <#  
   .SYNOPSIS  
   PowerShell function to get network Latency details  
   .DESCRIPTION  
   Includes parameters to monitor server and latecy, and capture data in file.  
   .EXAMPLE  
   Ping-Latency -ComputerName 127.0.0.1, MyRemote, 192.168.33.40 -Latency 100 -Hours 1 -File c:\temp\CapturedData.csv  
   #>   
   [CmdletBinding()]  
     param(  
     [Parameter(Mandatory=$False, ValueFromPipeline=$true,  
           HelpMessage="Enter one or more computer names separated by commas.")]  
     [alias("Computer","C")]  
     [string[]]$ComputerNames = $env:COMPUTERNAME,  
     [Parameter(Mandatory=$False)]  
     [alias("Latency","L")]  
     [string]$LatencytoMonitor = 100,  
     [Parameter(Mandatory=$False)]  
     [alias("Hour","H")]  
     [string]$Hours = 1,  
     [Parameter(Mandatory=$False)]  
     [alias("File","F")]  
     [string]$filename = "$env:USERPROFILE\Desktop"  
     )  
   Begin {  
     $time = $(Get-Date).AddMinutes($Hours)  
     $futuretime = "{0}:{1}" -f $time.Hour, $time.Minute  
   }  
   Process {  
     do  
     {  
       foreach ($Computer in $ComputerNames) {  
         $PingStatus = Test-Connection -ComputerName $computer -Count 1 -ErrorAction SilentlyContinue   
         if ($PingStatus -eq $null) {  
           $TestResult = "" | Select-Object Hostname, IPAddress, "Time-ms", DateTime  
           $TestResult.Hostname = $computer  
           $TestResult.IpAddress = "NotReachable"  
           $TestResult."Time-ms" = "RequestTimeOut"  
           $TestResult.DateTime = Get-Date  
           $TestResult | Export-Csv -Path $filename -Append -NoTypeInformation  
         }  
         elseif ($Pingstatus.ResponseTime -gt $LatencytoMonitor) {  
           $TestResult = "" | Select-Object Hostname, IPAddress, "Time-ms", DateTime  
           $TestResult.Hostname = $computer  
           $TestResult.IpAddress = $pingstatus.IPV4Address  
           $TestResult."Time-ms" = $pingstatus.ResponseTime  
           $TestResult.DateTime = Get-Date  
           $TestResult | Export-Csv -Path $filename -Append -NoTypeInformation  
         }  
         else {  
           #Write-Host "Ping response time to $computer is normal $($pingstatus.ResponseTime)"  
         }  
         $RealTime = Get-Date  
         $currenttime = "{0}:{1}" -f $RealTime.Hour, $RealTime.Minute  
       }  
     }  
     while ($CurrentTime -ne $futuretime)  
   }  
   End {}  
 }  

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

Keywords: capture ping request timed out and high latency

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

Thursday, September 4, 2014

VMware Networking 101: Network Failure Detection – Part 3



There are two types of Network Failure Detection options available in ESXi to detect network failure. It determines uplink status.

  • Link Status Only
  • Beacon Probing

Link Status only is very simple, default option and recommended setting for most of the designs, as shown in the video it will detect if physical NIC or cable issue till the connected upstream switch only. It is similar to some kind of Layer 1 (Physical Layer) faults in networking.


Beacon Probing as name implies it broadcasts beacon through one uplink and hear it on another uplink. It will detect network failures beyond the connected upstream switches, if you are planning to use this setting it is recommended at lease have 3 NICs connected, (With at least 3 NICs connected esxi can detect correct failure as shown in the video).


http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1005577

Although it looks like Beacon Probing is very fancy settings but still it is used less in esxi production environment. Due to Drops beyond the upstream switch can cause esxi to think NIC is down.

VMware Networking 101: VMware Network Load Balancing policies – Part 1
VMware Networking 101: VLAN handling in vSwitches – Part 2
VMware Networking 101: Network Failure Detection – Part 3
VMware Networking 101: vSwitches or PortGroup Security Settings – Part 4
Disclaimer:
This is a personal weblog. The opinions expressed here represent my own. If you find any correction need to be done or anything inappropriate, Feel free to comment on the post.