Fix ping latency to use actual RTT instead of subprocess time

Parse the real RTT from ping output instead of measuring subprocess
execution time, which included process startup overhead.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-26 19:38:37 +01:00
parent b0d571ae26
commit 06e1d683b3

View File

@@ -4,8 +4,8 @@ Checker Ping.
Vérifie la disponibilité d'un hôte via ICMP ping.
"""
import re
import subprocess
import time
import platform
from .base import BaseChecker, CheckResult
@@ -41,7 +41,6 @@ class PingChecker(BaseChecker):
else:
cmd = ["ping", "-c", str(count), "-W", str(timeout), host]
start = time.time()
try:
result = subprocess.run(
cmd,
@@ -49,9 +48,12 @@ class PingChecker(BaseChecker):
text=True,
timeout=timeout + 5
)
response_time = (time.time() - start) * 1000 # ms
if result.returncode == 0:
# Parse RTT from ping output (e.g., "time=0.32 ms" or "time=0.32ms")
match = re.search(r"time[=<]([\d.]+)\s*ms", result.stdout)
response_time = float(match.group(1)) if match else None
return CheckResult(
success=True,
message="Host is reachable",