diff --git a/clients/report_ping b/clients/report_ping index 6c18bec..f6b1923 100755 --- a/clients/report_ping +++ b/clients/report_ping @@ -24,15 +24,19 @@ now = time.time() p = subprocess.run(["/bin/ping", "-c", "20", "-i", "0.2", "-n", args.hostname], capture_output=True, text=True) report0 = [] for ln in p.stdout.split("\n")[:-1]: - if m := re.match(r"(\d+) packets transmitted, (\d+) received, (\d+)% packet loss", ln): + m = re.match(r"(\d+) packets transmitted, (\d+) received, (\d+)% packet loss", ln) + if m: report0.append({ "measure": "ping_transmitted", "unit": "packets", "value": int(m.group(1)) }) report0.append({ "measure": "ping_received", "unit": "packets", "value": int(m.group(2)) }) report0.append({ "measure": "ping_loss", "unit": "%", "value": int(m.group(3)) }) - elif m := re.match(r"rtt min/avg/max/mdev = ([0-9.]+)/([0-9.]+)/([0-9.]+)/([0-9.]+) ms", ln): + continue + m = re.match(r"rtt min/avg/max/mdev = ([0-9.]+)/([0-9.]+)/([0-9.]+)/([0-9.]+) ms", ln) + if m: report0.append({ "measure": "ping_min_rtt", "unit": "s", "value": float(m.group(1)) / 1000 }) report0.append({ "measure": "ping_avg_rtt", "unit": "s", "value": float(m.group(2)) / 1000 }) report0.append({ "measure": "ping_max_rtt", "unit": "s", "value": float(m.group(3)) / 1000 }) report0.append({ "measure": "ping_mdev_rtt", "unit": "s", "value": float(m.group(4)) / 1000 }) + continue if len(report0) != 7: print("Partial results:", report0)