Skip to content

Commit

Permalink
Add option to aggregate data from all interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
guiniol committed Dec 26, 2016
1 parent 56da7ba commit 730059e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion py3status/modules/net_rate.py
Expand Up @@ -23,6 +23,8 @@
(default 'lo')
si_units: use SI units
(default False)
sum_values: sum values of each interface instead of taking the top one
(default False)
thresholds: thresholds to use for colors
(default [(0, 'bad'), (1024, 'degraded'), (1024 * 1024, 'good')])
unit: unit to use. If the unit contains a multiplier prefix, only this
Expand Down Expand Up @@ -66,6 +68,7 @@ class Py3status:
interfaces = []
interfaces_blacklist = 'lo'
si_units = False
sum_values = False
thresholds = [(0, "bad"), (1024, "degraded"), (1024 * 1024, "good")]
unit = "B/s"

Expand Down Expand Up @@ -126,7 +129,13 @@ def currentSpeed(self):
self.last_time = time()

# get the interface with max rate
interface = max(deltas, key=lambda x: deltas[x]['total'])
if self.sum_values:
interface = 'sum'
sum_up = sum([itm['up'] for _, itm in deltas.items()])
sum_down = sum([itm['down'] for _, itm in deltas.items()])
deltas[interface] = {'total': sum_up + sum_down, 'up': sum_up, 'down': sum_down}
else:
interface = max(deltas, key=lambda x: deltas[x]['total'])

# if there is no rate - show last active interface, or hide
if deltas[interface]['total'] == 0:
Expand Down

0 comments on commit 730059e

Please sign in to comment.