Files
TCP_ping_monitor/README.md
JBg 865c0aee14 Update README.md
Fixed filename.
2025-03-12 08:32:59 +01:00

174 lines
5.5 KiB
Markdown

# TCP Ping Network Monitor
A PowerShell-based monitoring tool that checks port 80 connectivity for specified IP addresses while simultaneously monitoring network traffic. This tool provides real-time visibility into both web service availability and network bandwidth usage.
## Features
- **Port 80 Connectivity Monitoring**: Tests TCP connections to port 80 on specified IP addresses
- **Parallel Processing**: Uses PowerShell runspaces for efficient concurrent monitoring
- **Network Traffic Analysis**: Monitors upload/download speeds on a specified network interface
- **High Traffic Detection**: Alerts when network traffic exceeds defined thresholds
- **Performance Metrics**: Tracks min/max/mean response times and success rates
- **Traffic Correlation**: Links connection failures with high traffic events
## Getting Started
### Prerequisites
- Windows with PowerShell 3.0 or later
- Administrative privileges (recommended for WMI access to network interface data)
- Network interface named "Intel[R] I210 Gigabit Network Connection _2" (or modify the script to match your interface)
### Installation
1. Download the `Port80Monitor.ps1` script
2. No additional installation required
### Usage
Run the script in PowerShell with administrator privileges:
```powershell
.\TCP_Ping_Monitor.ps1
```
The script will continuously monitor the specified IP addresses and network traffic until manually stopped by pressing `Ctrl+C`.
## Configuration
### IP Addresses
Modify the `$addresses` array at the top of the script to monitor your desired IP addresses:
```powershell
$addresses = @(
"1.1.1.1",
"1.0.0.1"
# Add more IP addresses as needed
)
```
### Network Interface
The script is configured to monitor a specific network interface. Modify the `Get-NetworkTraffic` function to match your system's network interface name:
```powershell
$stats = Get-WmiObject Win32_PerfFormattedData_Tcpip_NetworkInterface |
Where-Object {$_.Name -eq "Intel[R] I210 Gigabit Network Connection _2"}
```
To find your network interface names, run:
```powershell
Get-WmiObject Win32_PerfFormattedData_Tcpip_NetworkInterface | Select-Object Name
```
### Traffic Thresholds
The high traffic threshold is set to 80 Mbps for both upload and download. Modify these values as needed:
```powershell
$isHighTrafficNow = ($uploadMbps -gt 80) -or ($downloadMbps -gt 80)
```
And:
```powershell
if ($uploadMbps -gt 80) {
$trafficStats.HighUploadInstances++
$uploadAlert = "HIGH UPLOAD ALERT: $([math]::Round($uploadMbps, 2)) Mbps"
}
```
## Console Display
The console display shows:
### Network Traffic Section
- Current download and upload speeds in Mbps
- Count of high traffic instances detected
- Alerts when traffic exceeds thresholds (displayed in red)
### Port 80 Connectivity Section
- **IP Address**: The address being monitored
- **Status**: UP (green) or DOWN (red)
- **Min**: Minimum response time in milliseconds
- **Max**: Maximum response time in milliseconds
- **Mean**: Average response time in milliseconds
- **Success%**: Percentage of successful connections
- **Fails**: Total count of failed connections
- **HTFails**: Count of failures during high traffic periods
## Log Files
The script creates a log file named `network_traffic.log` in the current directory with CSV-formatted data containing:
- Timestamp
- Bytes received per second
- Bytes sent per second
- High download alert flag (true/false)
- High upload alert flag (true/false)
This log can be used for later analysis and correlation between network traffic and service availability.
## Performance Considerations
- The script uses a runspace pool with a maximum of 20 concurrent runspaces, which balances efficiency with system resource usage
- Monitoring frequency is set to approximately 500ms (adjustable via the `Start-Sleep` parameter)
- The script maintains a rolling 60-sample window for calculating statistics
## Advanced Usage
### Monitoring Web Services
This tool is particularly useful for monitoring web services that:
- Run on port 80 (HTTP)
- May be affected by network congestion
- Require continuous availability monitoring
### Network Troubleshooting
Use this tool to:
- Identify correlation between network congestion and service failures
- Detect patterns in high traffic occurrences
- Monitor the impact of network changes on service availability
### Integration with Other Tools
The CSV log file can be:
- Imported into Excel or PowerBI for visualization
- Processed by other monitoring tools
- Used to generate reports on service levels and network performance
## Troubleshooting
Common issues:
1. **WMI Access Errors**: Ensure you're running PowerShell as Administrator
2. **Network Interface Not Found**: Verify the interface name in the `Get-NetworkTraffic` function
3. **Inaccurate Traffic Data**: Some virtualized environments may not report network statistics accurately
## Customization
### Adding Additional Metrics
You can extend the script to monitor additional metrics by:
- Adding new fields to the `$stats` hashtable
- Implementing additional WMI queries in the `Get-NetworkTraffic` function
- Expanding the display to show the new metrics
### Monitoring Different Ports
To monitor a different port (e.g., port 443 for HTTPS):
- Modify the port number in the `$TestPort80ScriptBlock` scriptblock:
```powershell
$result = $tcpClient.BeginConnect($ComputerName, 443, $null, $null)
```
## License
This script is provided as-is with no warranty. Use at your own risk.
## Acknowledgments
- PowerShell runspace pattern for efficient parallel execution
- Windows WMI for providing network performance data