1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-25 18:38:30 +00:00

Merge pull request #1391 from kimheino/master

knot: add support for mod-cookies and mod-rrl statistics
This commit is contained in:
Kenyon Ralph 2023-10-09 12:54:42 -07:00 committed by GitHub
commit 4abd859e6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: disable=invalid-name # pylint: disable=invalid-name
# pylint: enable=invalid-name # pylint: enable=invalid-name
# pylint: disable=consider-using-f-string
"""Munin plugin to monitor Knot DNS server. """Munin plugin to monitor Knot DNS server.
@ -90,6 +91,16 @@ CONFIG = {
'vlabel': 'operations / second', 'vlabel': 'operations / second',
'info': '', 'info': '',
}, },
'cookies': {
'title': 'cookies',
'vlabel': 'queries / second',
'info': '',
},
'rrl': {
'title': 'response rate limiting',
'vlabel': 'queries / second',
'info': '',
},
} }
@ -124,25 +135,30 @@ def get_stats():
# instead, needed for plugin config when using munin-async. # instead, needed for plugin config when using munin-async.
cachename = os.path.join(os.getenv('MUNIN_PLUGSTATE'), 'knot.state') cachename = os.path.join(os.getenv('MUNIN_PLUGSTATE'), 'knot.state')
if len(output) > 2048: if len(output) > 2048:
with open(cachename, 'wt') as cache: with open(cachename, 'wt', encoding='utf-8') as cache:
cache.write(output) cache.write(output)
elif ( elif (
os.path.exists(cachename) and os.path.exists(cachename) and
os.stat(cachename).st_mtime > time.time() - 900 os.stat(cachename).st_mtime > time.time() - 900
): ):
with open(cachename, 'rt') as cache: with open(cachename, 'rt', encoding='utf-8') as cache:
output = cache.read() output = cache.read()
# Parse output. Keep graph labels in knotc-order. # Parse output. Keep graph labels in knotc-order.
values = defaultdict(dict) values = defaultdict(dict)
for line in output.splitlines(): for line in output.splitlines():
if not line.startswith('mod-stats.') or ' = ' not in line: # Parse line to key1.key2 = value
if ' = ' not in line:
continue continue
# Parse key
key, value = line.split(' = ', 1) key, value = line.split(' = ', 1)
key = key[10:-1] if key.startswith('mod-stats.'):
key1, key2 = key.split('[', 1) # "mod-stats.server-operation[axfr] = 7"
key1, key2 = key[10:-1].split('[', 1)
elif key.startswith(('mod-cookies.', 'mod-rrl.')):
# "mod-cookies.presence = 94647"
key1, key2 = key[4:].split('.', 1)
else:
continue
# Parse value # Parse value
try: try: