提交 f5ea9e8f 编写于 作者: N nicolargo

Add color to nf_conn-track'

上级 7c87d343
......@@ -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)
......
......@@ -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
......@@ -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
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册