knot_exporter
knot_exporter copied to clipboard
AttributeError: 'int' object has no attribute 'items'
I get the error in the title when I run the command:
/opt/prometheus/exporters/knot/knot_exporter --web-listen-port 9433 --knot-socket-path /run/knot/knot.sock --knot-library-path /usr/lib/x86_64-linux-gnu/libknot.so
Here is the stack trace:
Traceback (most recent call last):
File "/opt/prometheus/exporters/knot/knot_exporter", line 496, in <module>
REGISTRY.register(KnotCollector(
File "/usr/lib/python3/dist-packages/prometheus_client/registry.py", line 24, in register
names = self._get_names(collector)
File "/usr/lib/python3/dist-packages/prometheus_client/registry.py", line 64, in _get_names
for metric in desc_func():
File "/opt/prometheus/exporters/knot/knot_exporter", line 447, in collect
for kind, kind_data in item_data.items():
AttributeError: 'int' object has no attribute 'items'
Any idea what's wrong?
@rhclayto Could you try a forked version with some fixes? https://github.com/salzmdan/knot_exporter
@rhclayto Could you try a forked version with some fixes? https://github.com/salzmdan/knot_exporter
Yes, thanks so much, it worked for me. I did however have to make one change:
REGISTRY.register(KnotCollector(
args.knot_library_path,
args.knot_socket_path,
args.knot_socket_timeout,
args.no_meminfo,
args.no_global_stats,
args.no_zone_stats,
args.no_zone_status,
args.no_zone_read,
))
to
REGISTRY.register(KnotCollector(
args.knot_library_path,
args.knot_socket_path,
args.knot_socket_timeout,
args.no_meminfo,
args.no_global_stats,
args.no_zone_stats,
args.no_zone_status,
args.no_zone_timers,
))
args.no_zone_read, -> args.no_zone_timers,
Without this change I was getting AttributeError: 'Namespace' object has no attribute args.no_zone_read.
Hi,
I am also affected by this issue, so I tried the fork as well. I needed to manually install libknot, pidof and psutil. However it fails anyway:
Traceback (most recent call last):
File "/usr/local/bin/knotexporter", line 217, in <module>
REGISTRY.register(KnotCollector(
File "/usr/local/lib/python3.9/site-packages/prometheus_client/registry.py", line 40, in register
names = self._get_names(collector)
File "/usr/local/lib/python3.9/site-packages/prometheus_client/registry.py", line 80, in _get_names
for metric in desc_func():
File "/usr/local/bin/knotexporter", line 76, in collect
for pid, usage in memory_usage().items():
File "/usr/local/bin/knotexporter", line 24, in memory_usage
key = int(pid)
ValueError: invalid literal for int() with base 10: b'\n'
I am using knot 3.3.0 on FreeBSD 13.2-p1
Here's the fix:
diff --git a/knot_exporter.py b/knot_exporter.py
index 8b1ce4e..3d16b27 100755
--- a/knot_exporter.py
+++ b/knot_exporter.py
@@ -19,6 +19,7 @@ def memory_usage():
out = dict()
pids = subprocess.check_output(['pidof', 'knotd']).split(b' ')
for pid in pids:
+ pid = pid.rstrip()
if not pid:
continue
key = int(pid)
Without it, one pid contained a newline, so the empty string test failed and it tried to convert that into an integer.
Here's the fix:
diff --git a/knot_exporter.py b/knot_exporter.py index 8b1ce4e..3d16b27 100755 --- a/knot_exporter.py +++ b/knot_exporter.py @@ -19,6 +19,7 @@ def memory_usage(): out = dict() pids = subprocess.check_output(['pidof', 'knotd']).split(b' ') for pid in pids: + pid = pid.rstrip() if not pid: continue key = int(pid)Without it, one pid contained a newline, so the empty string test failed and it tried to convert that into an integer.
Does this patch work https://gitlab.nic.cz/knot/knot-dns/-/commit/7e293321a4cf895078e6fa83bbb5b9cab181eb66.patch ?
Yes it works!
Do I see this right, knot_exporter.py is going to be part of the official distribution? Great!
kind regards, Tom
Fixed by https://gitlab.nic.cz/knot/knot-dns/-/commit/07f5c3970fffce23b625d9a8cae947e1699fa722
Yes, knot-exporter has been included in knot. Also you can find it as https://pypi.org/project/knot-exporter/