seperate up and down speeds for traffic widget

This commit is contained in:
Abin Simon 2017-04-21 11:40:02 +05:30
parent d3e24c0eea
commit a8693dcada
2 changed files with 30 additions and 11 deletions

View file

@ -8,10 +8,21 @@ import bumblebee.engine
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
def __init__(self, engine, config): def __init__(self, engine, config):
widgets = [] widgets = [
bumblebee.output.Widget(name="traffic.down"),
bumblebee.output.Widget(name="traffic.up"),
]
super(Module, self).__init__(engine, config, widgets) super(Module, self).__init__(engine, config, widgets)
self._exclude = tuple(filter(len, self.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(","))) self._exclude = tuple(filter(len, self.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
self._update_widgets(widgets) self._update_widgets(widgets)
self._status = None
def state(self, widget):
if widget.name == "traffic.down":
return "down"
if widget.name == "traffic.up":
return "up"
return self._status
def update(self, widgets): def update(self, widgets):
self._update_widgets(widgets) self._update_widgets(widgets)
@ -30,16 +41,23 @@ class Module(bumblebee.engine.Module):
_up = re.compile(r"TX packets .* bytes (.*) \(", re.MULTILINE) _up = re.compile(r"TX packets .* bytes (.*) \(", re.MULTILINE)
_current_up = re.search(_up,re.search(_block,_ifconfdata).group(0)).group(1) _current_up = re.search(_up,re.search(_block,_ifconfdata).group(0)).group(1)
widget = self.widget("traffic") widget_down = self.widget("traffic.down")
if not widget: widget_up = self.widget("traffic.up")
widget = bumblebee.output.Widget(name="traffic") if not widget_down:
widgets.append(widget) widget_down = bumblebee.output.Widget(name="traffic.down")
_prev_up = widget.get("absup", 0) widgets.append(widget_down)
_prev_down = widget.get("absdown", 0) if not widget_up:
widget_up = bumblebee.output.Widget(name="traffic.down")
widgets.append(widget_up)
_prev_down = widget_down.get("absdown", 0)
_speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down)) _speed_down = bumblebee.util.bytefmt(int(_current_down) - int(_prev_down))
widget_down.full_text("{}".format(_speed_down))
widget_down.set("absdown", _current_down)
_prev_up = widget_up.get("absup", 0)
_speed_up = bumblebee.util.bytefmt(int(_current_up) - int(_prev_up)) _speed_up = bumblebee.util.bytefmt(int(_current_up) - int(_prev_up))
widget.full_text("{} {}".format(_speed_down, _speed_up)) widget_up.full_text("{}".format(_speed_up))
widget.set("absdown", _current_down) widget_up.set("absup", _current_up)
widget.set("absup", _current_up)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -80,6 +80,7 @@
"prefix": "🌡" "prefix": "🌡"
}, },
"traffic":{ "traffic":{
"prefix": "" "down": { "prefix": "" },
"up": { "prefix": "" }
} }
} }