diff options
author | nicolargo <nicolas@nicolargo.com> | 2019-10-07 13:01:18 +0200 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2019-10-07 13:01:18 +0200 |
commit | f5ea9e8f4d637abf1d558fbdbc975a9abb43b475 (patch) | |
tree | 0da765289d9492ca5f43046f7611b9b52f9f12b1 | |
parent | 7c87d343eb12a8e3608d981a1ad20c86acf58ef3 (diff) |
Add color to nf_conn-track'
-rw-r--r-- | conf/glances.conf | 6 | ||||
-rw-r--r-- | docs/aoa/connections.rst | 8 | ||||
-rw-r--r-- | glances/plugins/glances_connections.py | 36 | ||||
-rw-r--r-- | glances/plugins/glances_plugin.py | 3 |
4 files changed, 27 insertions, 26 deletions
diff --git a/conf/glances.conf b/conf/glances.conf index bd9ca819..028def5a 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -26,7 +26,7 @@ max_processes_display=30 [quicklook] # Set to true to disable a plugin # Note: you can also disable it from the command line (see --disable-plugin) -disable=false +disable=False # Graphical percentage char used in the terminal user interface (default is |) percentage_char=| # Define CPU, MEM and SWAP thresholds in % @@ -143,6 +143,10 @@ tx_critical=90 # Display additional information about TCP connections # This plugin will be disable by default disable=True +# nf_conntrack thresholds in % +nf_conntrack_percent_careful=70 +nf_conntrack_percent_warning=80 +nf_conntrack_percent_critical=90 [wifi] # Define the list of hidden wireless network interfaces (comma-separated regexp) diff --git a/docs/aoa/connections.rst b/docs/aoa/connections.rst index b07733a9..320dcb29 100644 --- a/docs/aoa/connections.rst +++ b/docs/aoa/connections.rst @@ -7,19 +7,23 @@ Connections This plugin display extended information about network connections. - The states are the following: - Listen: all ports created by server and waiting for a client to connect - Initialized: All states when a connection is initialized (sum of SYN_SENT and SYN_RECEIVED) - Established: All established connections between a client and a server - Terminated: All states when a connection is terminated (FIN_WAIT1, CLOSE_WAIT, LAST_ACK, FIN_WAIT2, TIME_WAIT and CLOSE) +- Tracked: Current number and maximum Netfilter tracker connection (nf_conntrack_count/nf_conntrack_max) The configuration should be done in the ``[connections]`` section of the Glances configuration file. -By default the plugin is disabled. +By default the plugin is **disabled**. Please change your configuration file as following to enable it .. code-block:: ini [connections] disable=False + # nf_conntrack thresholds in % + nf_conntrack_percent_careful=70 + nf_conntrack_percent_warning=80 + nf_conntrack_percent_critical=90 diff --git a/glances/plugins/glances_connections.py b/glances/plugins/glances_connections.py index 29b2340a..cda7a1ba 100644 --- a/glances/plugins/glances_connections.py +++ b/glances/plugins/glances_connections.py @@ -20,6 +20,7 @@ """Connections plugin.""" from __future__ import unicode_literals +from glances.logger import logger from glances.timer import getTimeSinceLastUpdate from glances.plugins.glances_plugin import GlancesPlugin from glances.compat import n, u, b, nativestr @@ -103,6 +104,7 @@ class Plugin(GlancesPlugin): for i in self.conntrack: with open(self.conntrack[i], 'r') as f: stats[i] = float(f.readline().rstrip("\n")) + stats['nf_conntrack_percent'] = stats['nf_conntrack_count'] * 100 / stats['nf_conntrack_max'] elif self.input_method == 'snmp': # Update stats using SNMP @@ -119,34 +121,20 @@ class Plugin(GlancesPlugin): super(Plugin, self).update_views() # Add specifics informations - # Alert - # for i in self.stats: - # ifrealname = i['interface_name'].split(':')[0] - # # Convert rate in bps ( to be able to compare to interface speed) - # bps_rx = int(i['rx'] // i['time_since_update'] * 8) - # bps_tx = int(i['tx'] // i['time_since_update'] * 8) - # # Decorate the bitrate with the configuration file thresolds - # alert_rx = self.get_alert(bps_rx, header=ifrealname + '_rx') - # alert_tx = self.get_alert(bps_tx, header=ifrealname + '_tx') - # # If nothing is define in the configuration file... - # # ... then use the interface speed (not available on all systems) - # if alert_rx == 'DEFAULT' and 'speed' in i and i['speed'] != 0: - # alert_rx = self.get_alert(current=bps_rx, - # maximum=i['speed'], - # header='rx') - # if alert_tx == 'DEFAULT' and 'speed' in i and i['speed'] != 0: - # alert_tx = self.get_alert(current=bps_tx, - # maximum=i['speed'], - # header='tx') - # # then decorates - # self.views[i[self.get_key()]]['rx']['decoration'] = alert_rx - # self.views[i[self.get_key()]]['tx']['decoration'] = alert_tx + try: + # Alert and log + self.views['nf_conntrack_percent']['decoration'] = self.get_alert(header='nf_conntrack_percent') + except KeyError: + # try/except mandatory for Windows compatibility (no conntrack stats) + pass def msg_curse(self, args=None, max_width=None): """Return the dict to display in the curse interface.""" # Init the return message ret = [] + logger.info(self.is_disable()) + # Only process if stats exist and display plugin enable... if not self.stats or self.is_disable(): return ret @@ -169,6 +157,8 @@ class Plugin(GlancesPlugin): msg = '{:>{width}}'.format('{:0.0f}/{:0.0f}'.format(self.stats['nf_conntrack_count'], self.stats['nf_conntrack_max']), width=max_width - len(s) + 2) - ret.append(self.curse_add_line(msg)) + ret.append(self.curse_add_line(msg, + self.get_views(key='nf_conntrack_percent', + option='decoration'))) return ret diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 84c5cc2f..0856cac3 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -90,6 +90,9 @@ class GlancesPlugin(object): if not self.load_limits(config=config): logger.debug('Can not load section {} in {}'.format(self.plugin_name, config)) + else: + logger.debug('Load section {} in {}'.format(self.plugin_name, + config)) # Init the actions self.actions = GlancesActions(args=args) |