Add bitrate limits to the networks interfaces

pull/354/head
Nicolargo 2014-05-26 13:37:51 +02:00
parent 5961a947db
commit 8628f1e57a
3 changed files with 26 additions and 10 deletions

View File

@ -51,6 +51,13 @@ critical=90
[network]
# Define the list of hidden network interfaces (comma separeted)
hide=lo
# Default limits (in bits per second aka bps) for interface bitrate
wlan0_rx_careful=4000000
wlan0_rx_warning=5000000
wlan0_rx_critical=6000000
wlan0_tx_careful=700000
wlan0_tx_warning=900000
wlan0_tx_critical=1000000
[diskio]
# Define the list of hidden disks (comma separeted)

View File

@ -213,6 +213,7 @@ class Plugin(GlancesPlugin):
# Format stats
ifname = i['interface_name'].split(':')[0]
if args.byte:
# Bytes per second (for dummy)
if args.network_cumul:
rx = self.auto_unit(int(i['cumulative_rx']))
tx = self.auto_unit(int(i['cumulative_tx']))
@ -224,6 +225,7 @@ class Plugin(GlancesPlugin):
sx = self.auto_unit(int(i['rx'] // i['time_since_update'])
+ int(i['tx'] // i['time_since_update']))
else:
# Bits per second (for real network administrator | Default)
if args.network_cumul:
rx = self.auto_unit(int(i['cumulative_rx'] * 8)) + "b"
tx = self.auto_unit(int(i['cumulative_tx'] * 8)) + "b"
@ -243,8 +245,12 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
else:
msg = "{0:>7}".format(rx)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_add_line(msg,
self.get_alert(int(i['rx'] // i['time_since_update'] * 8),
header=ifname+'_rx')))
msg = "{0:>7}".format(tx)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_add_line(msg,
self.get_alert(int(i['tx'] // i['time_since_update'] * 8),
header=ifname+'_tx')))
return ret

View File

@ -176,14 +176,17 @@ class GlancesPlugin(object):
# Manage limits
ret = 'OK'
if value > self.__get_limit_critical(header=header):
ret = 'CRITICAL'
elif value > self.__get_limit_warning(header=header):
ret = 'WARNING'
elif value > self.__get_limit_careful(header=header):
ret = 'CAREFUL'
elif current < min:
ret = 'CAREFUL'
try:
if value > self.__get_limit_critical(header=header):
ret = 'CRITICAL'
elif value > self.__get_limit_warning(header=header):
ret = 'WARNING'
elif value > self.__get_limit_careful(header=header):
ret = 'CAREFUL'
elif current < min:
ret = 'CAREFUL'
except KeyError:
return 'DEFAULT'
# Manage log (if needed)
log_str = ""