sfudeus / homematic_exporter

Prometheus exporter for homematic ccu3
Apache License 2.0
23 stars 17 forks source link

Automatically retrieve device's room/function from CCU and pass as labels #59

Open flammermann opened 2 months ago

flammermann commented 2 months ago
sfudeus commented 2 months ago

Oh, interesting one, thx for the contribution, I'll have a look, just not sure when I get to it. Don't hesitate to nudge me again if it takes too long.

flammermann commented 2 months ago

Labels for channels and devices

After fiddling around in Grafana a bit, I got a better understanding of parent device and device. Which makes sense because it is coming like that from XML RPC. From XML RPC you get

The way this exporter is written, only metrics for devices with parent device are created. device without parent device are only used for logging and nothing else.

Therefore, I adjusted the naming of labels again to properly reflect which information belong to a channel which to a device. Also I differentiated the room and the function information for those two.

There are now the following metric labels:

Remove old metrics during runtime after mapping refresh

All these new labels make an already existing issue https://github.com/sfudeus/homematic_exporter/issues/30 more apparent. Whenever anything changes about this mapping/configuration of any channel/device, the old metric stays existent with the same value. This same value is scraped by Prometheus until eternity.

The second commit addresses this issue. Not 100% happy with the solution, but it works. The only downside is that the metric is unavailable for all devices (also those that are still existent) for a short period of time after resetting it. This means that in the time between reset and recreation of the metric for each device, the scrape from Prometheus would not find anything. This in turn causes missing values in Prometheus, but only if Prometheus scrapes exactly in those few second between reset and recreate. I checked in my own setup and I don't care about those few missing values.

If you have a better solution to this problem, feel free to adjust the code! I am sure there is, I just didn't have the time to find it.

flammermann commented 2 months ago

Update: Remove old metrics during runtime after mapping refresh

Found a better solution to this problem. Now I am storing all metrics that were added during a run and then every time the device mapping is refreshed all metrics in all collectors stored in self.metrics that are not in the list of metrics from the previous run, are removed from that collector.

before the whole collectors were removed from the registry, now only unused metrics are removed from the collectors. This still solves https://github.com/sfudeus/homematic_exporter/issues/30 but without the drawback of the earlier implementation (see comment above).