Built a a script to watch the conntrack levels inside all qrouter namespaces

This commit is contained in:
Cory Hawkless 2022-10-04 16:24:11 +10:30
parent 384eab9966
commit 27177cbd74
1 changed files with 6 additions and 4 deletions

View File

@ -5,12 +5,13 @@ from pyroute2 import netns, NSPopen
import socket
import time
registry = CollectorRegistry()
g_count = Gauge('test_nf_conntrack_count', 'nf_conntrack_count inside given namespace', ['host','namespace'],registry=registry )
g_max = Gauge('test_nf_conntrack_max', 'nf_conntrack_max inside given namespace', ['host','namespace'],registry=registry )
hostname=socket.gethostname()
while True:
registry = CollectorRegistry()
g_count = Gauge('test_nf_conntrack_count', 'nf_conntrack_count inside given namespace', ['host','namespace'],registry=registry )
g_max = Gauge('test_nf_conntrack_max', 'nf_conntrack_max inside given namespace', ['host','namespace'],registry=registry )
for _item in netns.listnetns():
if str(_item).startswith("qrouter"):
nsp = NSPopen(_item, ['cat', '/proc/sys/net/netfilter/nf_conntrack_count'], stdout=subprocess.PIPE)
@ -28,10 +29,11 @@ while True:
g_count.labels(hostname,_item).set(nsresult_count)
g_max.labels(hostname,_item).set(nsresult_max)
# exit()
push_to_gateway('10.10.110.250:9091', job='cory_test_job2', registry=registry)
time.sleep(30)
push_to_gateway('10.10.110.250:9091', job='cory_test_job2', registry=registry)
# print("Done")
# # curl -X GET http://10.10.110.250:9091/api/v1/metrics | jq