mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-21 00:01:53 +03:00
Add conntrack
This commit is contained in:
parent
dcd28b778d
commit
7c87d343eb
@ -51,6 +51,8 @@ class Plugin(GlancesPlugin):
|
||||
psutil.CONN_CLOSE,
|
||||
psutil.CONN_CLOSE_WAIT,
|
||||
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):
|
||||
"""Init the plugin."""
|
||||
@ -62,6 +64,8 @@ class Plugin(GlancesPlugin):
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
||||
# @TODO the plugin should be enable only for Linux OS
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
def update(self):
|
||||
@ -95,6 +99,11 @@ class Plugin(GlancesPlugin):
|
||||
terminated += stats[s]
|
||||
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':
|
||||
# Update stats using SNMP
|
||||
pass
|
||||
@ -152,5 +161,14 @@ class Plugin(GlancesPlugin):
|
||||
ret.append(self.curse_add_line(msg))
|
||||
msg = '{:>{width}}'.format(self.stats[s], width=max_width - len(s) + 2)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user