Skip to content

allenunrau/ltping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 

Repository files navigation

ltping β€” Long-Term Ping Monitor

A beautiful, real-time CLI tool for monitoring network latency over configurable time windows. Track ping statistics with live updates, color-coded metrics, and sliding window analytics.

ltping demo

Features

  • πŸ“Š Sliding Window Statistics β€” Track metrics across multiple configurable time periods (10s, 1m, 5m, 1h, etc.)
  • 🎨 Live Color-Coded Display β€” Green for healthy, yellow for moderate, red for critical latency/loss
  • ⚑ Real-Time Updates β€” In-place refresh shows evolving stats as old pings age out of each window
  • πŸ”’ No Root Required β€” Uses unprivileged ICMP sockets (works on most modern Linux systems)
  • πŸ“ˆ Comprehensive Metrics β€” Min/Max/Avg RTT, packet loss percentage, and network jitter
  • ⌨️ Simple & Intuitive β€” Clean interface, sensible defaults, easy to customize

Quick Start

# Clone the repository
git clone https://github.com/yourusername/ltping.git
cd ltping

# Make it executable
chmod +x ltping.py

# Run with default settings (10s / 30s / 60s windows)
python3 ltping.py google.com

Installation

Requirements

  • Python 3.10 or newer
  • Linux with kernel support for unprivileged ICMP sockets

System Setup

Most modern Linux distributions allow unprivileged ping sockets by default. If you see a "ping_group_range" error on first run, fix it with:

sudo sysctl -w net.ipv4.ping_group_range='0 2147483647'

To make this permanent across reboots:

echo 'net.ipv4.ping_group_range = 0 2147483647' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Usage

Basic Examples

# Default: monitor with 10s, 30s, and 60s windows
python3 ltping.py google.com

# Ping an IP address
python3 ltping.py 8.8.8.8

# Custom time windows
python3 ltping.py example.com -w 5s 15s 60s 5m

# Fast ping interval (500ms between pings)
python3 ltping.py 1.1.1.1 -i 0.5

# Long-term monitoring with multiple windows
python3 ltping.py example.com -w 10s 1m 5m 30m 1h

Command-Line Options

ltping [-h] [-w WINDOWS [WINDOWS ...]] [-i INTERVAL] [-t TIMEOUT] [--no-color] target

Positional arguments:
  target                Hostname or IP address to ping

Options:
  -h, --help            Show help message and exit
  -w, --windows         Time windows (e.g. 10s 30s 60s 5m 1h)
                        Default: 10s 30s 60s
  -i, --interval        Seconds between pings (default: 1.0)
  -t, --timeout         Seconds to wait for each reply (default: 2.0)
  --no-color            Disable colored output

Window Specifications

Time windows can be specified in seconds (s), minutes (m), or hours (h):

  • 10s β€” 10 seconds
  • 5m β€” 5 minutes (300 seconds)
  • 1h β€” 1 hour (3600 seconds)
  • 30 β€” Plain numbers are treated as seconds

Output Format

ltping  google.com  (142.250.80.46)  seq=42  last=15.3 ms  lifetime 42/42 (100.0%)
────────────────────────────────────────────────────────────────────────
 Window   Sent   Rcvd    Loss      Min      Max      Avg   Jitter
────────────────────────────────────────────────────────────────────────
    10s     10     10    0.0%    12 ms    18 ms    15 ms    2.1 ms
    30s     30     30    0.0%    12 ms    20 ms    15 ms    2.3 ms
    60s     60     59    1.7%    12 ms    25 ms    16 ms    3.1 ms
────────────────────────────────────────────────────────────────────────
Press Ctrl+C to stop.

Metrics Explained

  • Window β€” Time period for the rolling statistics
  • Sent β€” Total pings sent in this window
  • Rcvd β€” Pings that received a reply
  • Loss β€” Packet loss percentage (color-coded: green = 0%, yellow < 10%, red β‰₯ 10%)
  • Min/Max/Avg β€” Round-trip time statistics in milliseconds
  • Jitter β€” Average variation between consecutive RTTs (lower is better)

Color Coding

Packet Loss:

  • 🟒 Green: 0% loss
  • 🟑 Yellow: < 10% loss
  • 🟠 Orange: < 50% loss
  • πŸ”΄ Red: β‰₯ 50% loss

Latency (RTT):

  • 🟒 Bright Green: < 20ms (excellent)
  • πŸ”΅ Cyan: 20-100ms (good)
  • 🟑 Yellow: 100-300ms (moderate)
  • πŸ”΄ Red: > 300ms (high)

Jitter:

  • 🟒 Green: Low variance (< 20% of average RTT)
  • 🟑 Yellow: Moderate (20-50% of average)
  • πŸ”΄ Red: High variance (> 50% of average)

Use Cases

Network Troubleshooting

Monitor intermittent connectivity issues over extended periods:

python3 ltping.py gateway.local -w 1m 5m 15m 1h

ISP Performance Monitoring

Track your internet connection quality throughout the day:

python3 ltping.py 8.8.8.8 -w 5m 30m 1h 6h -i 2

Application Latency Testing

Measure response time to a remote service with high-frequency pings:

python3 ltping.py api.example.com -i 0.2 -w 10s 30s 60s

VPN Performance Analysis

Compare latency before and after VPN connection:

python3 ltping.py cloudflare.com -w 30s 2m 5m

How It Works

Sliding Windows: Each time window maintains a queue of recent ping results. As new pings arrive, old ones beyond the window duration are automatically dropped. This gives you real-time insight into recent network behavior.

Unprivileged ICMP: Uses SOCK_DGRAM with IPPROTO_ICMP β€” the Linux kernel's ping socket API. No raw sockets required, so no root privileges needed on most systems.

Jitter Calculation: Computed as the average of absolute differences between consecutive RTTs within each window. This helps identify network instability beyond simple packet loss.

Troubleshooting

"Cannot open ICMP ping socket" error

Your kernel's ping_group_range is restricted. Fix with:

sudo sysctl -w net.ipv4.ping_group_range='0 2147483647'

Or run with sudo as a one-time workaround:

sudo python3 ltping.py example.com

No colors in output

If you're piping output or using a non-TTY terminal, colors are automatically disabled. You can force disable with --no-color:

python3 ltping.py example.com --no-color > log.txt

High CPU usage

By default, ltping pings once per second. If you've set a very short interval (e.g., -i 0.01), it may consume more CPU. For most monitoring scenarios, 0.2-1.0 second intervals are sufficient.

Technical Details

  • Language: Python 3.10+
  • Dependencies: Standard library only (no pip packages required)
  • Protocol: ICMP Echo Request/Reply (RFC 792)
  • Socket Type: AF_INET, SOCK_DGRAM, IPPROTO_ICMP
  • Platform: Linux (kernel 2.6.39+)

Limitations

  • IPv4 only β€” IPv6 support is not currently implemented
  • Linux only β€” Uses Linux-specific ping socket API (won't work on macOS/Windows without modification)
  • Single target β€” Monitors one host at a time (run multiple instances for parallel monitoring)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

MIT License β€” see LICENSE file for details.

Acknowledgments

  • Inspired by traditional ping and network monitoring tools
  • Built with a focus on real-time visualization and user experience

See Also

  • ping β€” The original ICMP echo utility
  • mtr β€” Network diagnostic tool combining ping and traceroute
  • iperf β€” Network bandwidth measurement tool

Made with ❀️ for network engineers, sysadmins, and anyone who needs to know if their internet is actually working.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages