From 8628f1e57a138bec1754359356bcd0afa70031f0 Mon Sep 17 00:00:00 2001 From: Nicolargo Date: Mon, 26 May 2014 13:37:51 +0200 Subject: Add bitrate limits to the networks interfaces --- conf/glances-monitor.conf | 7 +++++++ glances/plugins/glances_network.py | 10 ++++++++-- glances/plugins/glances_plugin.py | 19 +++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/conf/glances-monitor.conf b/conf/glances-monitor.conf index a696149c..c9f6338b 100644 --- a/conf/glances-monitor.conf +++ b/conf/glances-monitor.conf @@ -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) diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index f5c5292f..d8e96315 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -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 diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 3f2f9ec3..700739e3 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -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 = "" -- cgit v1.2.3