Logging Network Latency and Correlating It with the Weather

Network performance is often judged from isolated incidents. Recording latency over time makes it possible to compare observations against other conditions, such as weather, rather than relying on memory.

Ping Logger and Grapher records latency and overlays weather observations on its charts, making potential patterns easier to investigate.

Architecture: why multiple scripts?

The project uses separate scripts rather than one monolithic tool, which makes it easier to run each piece on a schedule independently:

# ping.py: simplified core loop
result = subprocess.run(["ping", "-n", "1", TARGET], capture_output=True, text=True)
latency = parse_latency(result.stdout)
weather = get_weather(OWM_API_KEY, CITY)

with open(LOG_FILE, "a") as f:
    f.write(f"{datetime.now()},{latency},{weather['description']},{weather['temp']}\n")

OpenWeatherMap integration

Each ping log entry includes a weather snapshot: conditions (clear, rain, overcast, etc.) and temperature. The OpenWeatherMap free tier is more than sufficient for this: one API call per ping interval is nowhere near the rate limits.

When you generate a graph, the weather conditions are rendered as a shaded background layer. Rain periods show as light blue shading, storms as darker blue. It makes the correlation between bad weather and elevated latency visually obvious, or proves it's not there.

Path resolution

Earlier versions required you to manually set file paths in each script, a pain when running from cron where the working directory is unpredictable. The current version uses __file__-relative paths throughout, so scripts always find their data files regardless of where they're invoked from.

BASE_DIR = Path(__file__).parent
LOG_DIR  = BASE_DIR / "logs"
ARCH_DIR = BASE_DIR / "archive"

The tool is designed to show potential correlations, not to establish causation. Results depend on the target host, connection, observation period, and local conditions.


← Back to all posts  ·  View on GitHub ↗