Created
December 17, 2015 14:37
-
-
Save alexanderfefelov/1ffca091e28cace0f043 to your computer and use it in GitHub Desktop.
Prints conntrack stats for protocols and connection states
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
protocols = dict() | |
connection_states = dict() | |
import subprocess | |
output = subprocess.check_output('conntrack -L', shell = True) | |
for row in output.split('\n'): | |
elements = row.split() | |
try: | |
element = elements[0] | |
if element in protocols: | |
protocols[element] += 1 | |
else: | |
protocols[element] = 1 | |
except IndexError: | |
pass | |
try: | |
element = elements[3] | |
if element[0].isupper(): | |
if element in connection_states: | |
connection_states[element] += 1 | |
else: | |
connection_states[element] = 1 | |
except IndexError: | |
pass | |
print protocols | |
print connection_states |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: