summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-08-24 19:24:01 +0200
committerGitHub <noreply@github.com>2022-08-24 19:24:01 +0200
commita87e4fcc351295fb27fb781b042fc6f798e5cd0e (patch)
tree1c28a5ddfdf09c2161b84fb9a96dafd92935b984 /src
parentdd2855ceb243b78d197227cff928a6af85676dec (diff)
parent9b3cdfb96af98d479cb804c69baa68c1ad50b48f (diff)
downloadvyos-1x-a87e4fcc351295fb27fb781b042fc6f798e5cd0e.tar.gz
vyos-1x-a87e4fcc351295fb27fb781b042fc6f798e5cd0e.zip
Merge pull request #1489 from sever-sever/T4623
conntrack: T4623: Add conntrack statistics for op-mode
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/conntrack.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/op_mode/conntrack.py b/src/op_mode/conntrack.py
index 036226418..b27aa6060 100755
--- a/src/op_mode/conntrack.py
+++ b/src/op_mode/conntrack.py
@@ -51,6 +51,21 @@ def _get_raw_data(family):
return _xml_to_dict(xml)
+def _get_raw_statistics():
+ entries = []
+ data = cmd('sudo conntrack -S')
+ data = data.replace(' \t', '').split('\n')
+ for entry in data:
+ entries.append(entry.split())
+ return entries
+
+
+def get_formatted_statistics(entries):
+ headers = ["CPU", "Found", "Invalid", "Insert", "Insert fail", "Drop", "Early drop", "Errors", "Search restart"]
+ output = tabulate(entries, headers, numalign="left")
+ return output
+
+
def get_formatted_output(dict_data):
"""
:param xml:
@@ -111,6 +126,14 @@ def show(raw: bool, family: str):
return get_formatted_output(conntrack_data)
+def show_statistics(raw: bool):
+ conntrack_statistics = _get_raw_statistics()
+ if raw:
+ return conntrack_statistics
+ else:
+ return get_formatted_statistics(conntrack_statistics)
+
+
if __name__ == '__main__':
try:
res = vyos.opmode.run(sys.modules[__name__])