[modules/traffic] add format parameter
This commit is contained in:
parent
fd72d84fec
commit
36c9a24ac4
1 changed files with 7 additions and 2 deletions
|
@ -6,6 +6,8 @@ Parameters:
|
||||||
* traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth")
|
* traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth")
|
||||||
* traffic.states: Comma-separated list of states to show (prefix with "^" to invert - i.e. ^down -> show all devices that are not in state down)
|
* traffic.states: Comma-separated list of states to show (prefix with "^" to invert - i.e. ^down -> show all devices that are not in state down)
|
||||||
* traffic.showname: If set to False, hide network interface name (defaults to True)
|
* traffic.showname: If set to False, hide network interface name (defaults to True)
|
||||||
|
* traffic.format: Format string for download/upload speeds.
|
||||||
|
Defaults to "{:.2f}"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
@ -25,6 +27,7 @@ class Module(bumblebee.engine.Module):
|
||||||
self._status = ""
|
self._status = ""
|
||||||
|
|
||||||
self._showname = bumblebee.util.asbool(self.parameter("showname", True))
|
self._showname = bumblebee.util.asbool(self.parameter("showname", True))
|
||||||
|
self._format = self.parameter("format", "{:.2f}")
|
||||||
self._prev = {}
|
self._prev = {}
|
||||||
self._states = {}
|
self._states = {}
|
||||||
self._lastcheck = 0
|
self._lastcheck = 0
|
||||||
|
@ -102,7 +105,9 @@ class Module(bumblebee.engine.Module):
|
||||||
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 = self._prev.get(name, 0)
|
prev = self._prev.get(name, 0)
|
||||||
speed = bumblebee.util.bytefmt((int(data[direction]) - int(prev))/timediff)
|
speed = bumblebee.util.bytefmt(
|
||||||
|
(int(data[direction]) - int(prev))/timediff,
|
||||||
|
self._format)
|
||||||
txtspeed = '{0}/s'.format(speed)
|
txtspeed = '{0}/s'.format(speed)
|
||||||
widget.full_text(txtspeed)
|
widget.full_text(txtspeed)
|
||||||
self._prev[name] = data[direction]
|
self._prev[name] = data[direction]
|
||||||
|
|
Loading…
Reference in a new issue