mweinelt / kea-exporter

Export Kea Metrics in the Prometheus Exposition Format
MIT License
34 stars 17 forks source link

KeyError: 'cumulative-assigned-addresses #18

Closed Tira007 closed 4 years ago

Tira007 commented 4 years ago

How to launch kea-exporter?

example 1

[root@southpark kea_exporter]# kea-exporter --address "127.0.0.1" --port 8001 /tmp/kea4-ctrl-socket
Listening on http://127.0.0.1:8001
Traceback (most recent call last):
  File "/usr/local/bin/kea-exporter", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/kea_exporter/cli.py", line 22, in cli
    exporter.update()
  File "/usr/local/lib/python3.6/site-packages/kea_exporter/kea.py", line 502, in update
    metric_info = self.metrics_dhcp4_map[key]
KeyError: 'cumulative-assigned-addresses'

example2

[root@southpark kea_exporter]# kea-exporter --address "localhost" --port 8001 /tmp/kea4-ctrl-socket
Listening on http://localhost:8001
Traceback (most recent call last):
  File "/usr/local/bin/kea-exporter", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/kea_exporter/cli.py", line 22, in cli
    exporter.update()
  File "/usr/local/lib/python3.6/site-packages/kea_exporter/kea.py", line 502, in update
    metric_info = self.metrics_dhcp4_map[key]
KeyError: 'cumulative-assigned-addresses

I would be grateful for an example.

mweinelt commented 4 years ago

This is probably due to new metrics, that kea-exporter does not handle (in this case ignore) yet. What Kea version is this?

mweinelt commented 4 years ago

Related to https://gitlab.isc.org/isc-projects/kea/-/merge_requests/729/diffs.

mweinelt commented 4 years ago

I've added a patch for you to try in the pull request above.

pmackey2 commented 4 years ago

I'm still seeing a KeyError with the patch applied.

I believe this is caused by a further instance of "cumulative-assigned-addresses" on each subnet which isn't captured by self.metrics_dhcp4_ignore.

echo '{ "command": "statistic-get-all" }' | socat UNIX:/sockets/kea-dhcp4-ctrl.sock -,ignoreeof | jq
{
  "arguments": {
    "cumulative-assigned-addresses": [
      [
        0,
        "2020-08-05 11:14:44.552701"
      ]
    ],
    ...... omitted for brevity .......
    ],
    "subnet[1].cumulative-assigned-addresses": [
      [
        0,
        "2020-08-05 11:14:45.591529"
      ]
    ...... omitted for brevity .......
  },
  "result": 0
}

Here is the traceback:

Traceback (most recent call last):
  File "/usr/bin/kea-exporter", line 11, in <module>
    load_entry_point('kea-exporter==0.4.1', 'console_scripts', 'kea-exporter')()
  File "/usr/lib/python3.8/site-packages/click-7.1.2-py3.8.egg/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/click-7.1.2-py3.8.egg/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.8/site-packages/click-7.1.2-py3.8.egg/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.8/site-packages/click-7.1.2-py3.8.egg/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/kea_exporter-0.4.1-py3.8.egg/kea_exporter/cli.py", line 22, in cli
  File "/usr/lib/python3.8/site-packages/kea_exporter-0.4.1-py3.8.egg/kea_exporter/kea.py", line 506, in update
KeyError: 'cumulative-assigned-addresses'
mweinelt commented 4 years ago

Then we could apply the same ignore rules to the per subnet metrics. Can you try this?

diff --git a/kea_exporter/kea.py b/kea_exporter/kea.py
index decc023..031af0e 100644
--- a/kea_exporter/kea.py
+++ b/kea_exporter/kea.py
@@ -485,6 +485,14 @@ class KeaExporter:
                         subnet_id = int(match.group('subnet_id'))
                         key = match.group('metric')

+                        if kea.dhcp_version is DHCPVersion.DHCP4:
+                            if key in self.metrics_dhcp4_ignore:
+                                continue
+                        elif kea.dhcp_version is DHCPVersion.DHCP6:
+                            if key in self.metrics_dhcp6_ignore:
+                                continue
+                        else:
+                            continue
                         try:
                             subnet = kea.subnets[subnet_id]
                         except KeyError:
pmackey2 commented 4 years ago

Yes, that resolves the issue. Thanks!