Add conntrack

This commit is contained in:
nicolargo 2019-09-28 18:16:26 +02:00
parent dcd28b778d
commit 7c87d343eb

View File

@ -51,6 +51,8 @@ class Plugin(GlancesPlugin):
psutil.CONN_CLOSE, psutil.CONN_CLOSE,
psutil.CONN_CLOSE_WAIT, psutil.CONN_CLOSE_WAIT,
psutil.CONN_LAST_ACK] psutil.CONN_LAST_ACK]
conntrack = {'nf_conntrack_count': '/proc/sys/net/netfilter/nf_conntrack_count',
'nf_conntrack_max': '/proc/sys/net/netfilter/nf_conntrack_max'}
def __init__(self, args=None, config=None): def __init__(self, args=None, config=None):
"""Init the plugin.""" """Init the plugin."""
@ -62,6 +64,8 @@ class Plugin(GlancesPlugin):
# We want to display the stat in the curse interface # We want to display the stat in the curse interface
self.display_curse = True self.display_curse = True
# @TODO the plugin should be enable only for Linux OS
@GlancesPlugin._check_decorator @GlancesPlugin._check_decorator
@GlancesPlugin._log_result_decorator @GlancesPlugin._log_result_decorator
def update(self): def update(self):
@ -95,6 +99,11 @@ class Plugin(GlancesPlugin):
terminated += stats[s] terminated += stats[s]
stats['terminated'] = terminated stats['terminated'] = terminated
# Grab connections track directly from the /proc file
for i in self.conntrack:
with open(self.conntrack[i], 'r') as f:
stats[i] = float(f.readline().rstrip("\n"))
elif self.input_method == 'snmp': elif self.input_method == 'snmp':
# Update stats using SNMP # Update stats using SNMP
pass pass
@ -152,5 +161,14 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(msg))
msg = '{:>{width}}'.format(self.stats[s], width=max_width - len(s) + 2) msg = '{:>{width}}'.format(self.stats[s], width=max_width - len(s) + 2)
ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(msg))
# Connections track
s = 'Tracked'
ret.append(self.curse_new_line())
msg = '{:{width}}'.format(nativestr(s).capitalize(), width=len(s))
ret.append(self.curse_add_line(msg))
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))
return ret return ret