From 2b5c85cb8c6a8164a25179f9f652fb9814d98c91 Mon Sep 17 00:00:00 2001 From: Justin Wheeler Date: Mon, 12 Jun 2017 22:18:49 -0400 Subject: [PATCH] Add packet loss to ping. Show packet loss in ping response. --- bumblebee/modules/ping.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/ping.py b/bumblebee/modules/ping.py index 469871a..e19d603 100644 --- a/bumblebee/modules/ping.py +++ b/bumblebee/modules/ping.py @@ -30,6 +30,11 @@ def get_rtt(module, widget): )) for line in res.split("\n"): + if line.startswith( "{} packets transmitted".format( widget.get( "rtt-probes" ) ) ): + m = re.search( r'(\d+)% packet loss', line ) + + widget.set( 'packet-loss', m.group(1) ) + if not line.startswith("rtt"): continue m = re.search(r'([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)', line) @@ -51,16 +56,18 @@ class Module(bumblebee.engine.Module): widget.set("rtt-timeout", self.parameter("timeout", 5.0)) widget.set("rtt-avg", 0.0) widget.set("rtt-unit", "") + widget.set('packet-loss', 0) self._next_check = 0 def rtt(self, widget): if widget.get("rtt-unreachable"): return "{}: unreachable".format(widget.get("address")) - return "{}: {:.1f}{}".format( + return "{}: {:.1f}{} ({}%)".format( widget.get("address"), widget.get("rtt-avg"), - widget.get("rtt-unit") + widget.get("rtt-unit"), + widget.get( 'packet-loss' ) ) def state(self, widget):