[modules/traffic] Fix delta calculation

A previous commit broke the traffic module by deleting widgets during
each iteration. This is fatal as the widgets contain the traffic
information from the previous iteration, for delta calculation.

Store previous traffic data in the module itself instead.
This commit is contained in:
Tobias Witek 2017-06-05 15:06:56 +02:00
parent 937e61a863
commit d48e661d97

View file

@ -23,6 +23,7 @@ class Module(bumblebee.engine.Module):
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._status = "" self._status = ""
self._prev = {}
self._states = {} self._states = {}
self._states["include"] = [] self._states["include"] = []
self._states["exclude"] = [] self._states["exclude"] = []
@ -90,9 +91,9 @@ class Module(bumblebee.engine.Module):
for direction in ["rx", "tx"]: for direction in ["rx", "tx"]:
name = "traffic.{}-{}".format(direction, interface) name = "traffic.{}-{}".format(direction, interface)
widget = self.create_widget(widgets, name, attributes={"theme.minwidth": "1000.00MB"}) widget = self.create_widget(widgets, name, attributes={"theme.minwidth": "1000.00MB"})
prev = widget.get(direction, 0) prev = self._prev.get(name, 0)
speed = bumblebee.util.bytefmt(int(data[direction]) - int(prev)) speed = bumblebee.util.bytefmt(int(data[direction]) - int(prev))
widget.full_text(speed) widget.full_text(speed)
widget.set(direction, data[direction]) self._prev[name] = data[direction]
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4