New Add-on bundle for Prometheus health Metrics

Oh, wow I’m very sorry I didn’t reply in time, somehow I didn’t get or notice the forum mail notifications :frowning:

Thanks @ricadelic for the detailed instructions. Actually it should be no problem to place all the .jar files into the addons folder at the same time or at a random order. @mdnx the link https://github.com/KuguHome/openhab-prometheus-metrics/releases/ as @ricadelic posted it is the right place to look. The bundle is currently running in several field systems for us in beta state, development is somewhat paused but we are very interested in feedback!

@imaginator I am not aware of a similar approach for a direct item Prometheus exporter.From our point of view, the InfluxDB or any other persistence plugin would be the “correct” way to get the item values (going MQTT->Prometheus seems one step too much for me). We instead wanted to get values/metrics, which were (until now) hidden. Also, to our mind, Prometheus is more of a health metrics monitoring tool and less of a general value scraper. But you can certainly use it that way. It also shouldn’t be too much of a problem, to write an “Exposable” along the lines of https://github.com/KuguHome/openhab-prometheus-metrics/blob/master/com.kuguhome.openhab.prometheusmetrics/src/main/java/com/kuguhome/openhab/prometheusmetrics/exposable/OpenHABThingStateMetric.java which queries the item registry instead of the thing registry and outputs their values.
If it would be “switchable” within the bundle, we could include it, if you do a PR on GitHub.

I haven’t set this this up myself yet, but my understand is that Prometheus users Grafana as the display. So there shouldn’t be anything stopping you from adding graphs of stuff saved to InfluxDB through Persistence to the same Graphana dashboard.

Grafana can display all kinds of data sources, including MySQL, Prometheus or InfluxDB, you can mix them on the same board or even on the same graph.

My thinking on Prometheus is less about the graphing and more about the Prometheus query functions. I’d love to be able to detect water leaks by looking for sustained low values. Or predict energy consumption for the rest of the month. Or hook into the Prometheus alert manager … Or… :grinning:

That’s actually a nice idea. As I said, it should be pretty easy to implement.

…next level awesome would be the ability to include PromQL in rules.

If prometheus(sum(count_over_time(basement-humidity[60m])), then...
1 Like

Very interesting suggestion :+1::+1:

Does anyone having this working with 2.5.0 release?

I get this error message:

[WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/openhab/addons/com.kuguhome.openhab.prometheusmetrics-2.4.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: com.kuguhome.openhab.prometheusmetrics [207]
  Unresolved requirement: Import-Package: io.swagger.annotations; version="1.5.7.SNAPSHOT"

@gersilex just mentioned to me that https://github.com/baaym/openhab2-prometheus-exporter now exists. I’ve got it running and it seems to work for exporting openhab item values. One small issue with UNDEFs.

Here’s the output:

# TYPE openhab2_metric_number gauge
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesMainBrushPercent"} 86 1557828884718
openhab2_metric_number{name="LocalSun_RadiationDiffuse"} 123.95447796048198 1557828884718
openhab2_metric_number{name="Hs110Fridge_Current"} 0.031 1557828884718
openhab2_metric_number{name="Hs110WashingMachine_EnergyUsage"} 4.878 1557828884718
openhab2_metric_number{name="Hs110GlassCubeLight_Current"} 0.034 1557828884718
openhab2_metric_number{name="Hs110IndustrialLight_EnergyUsage"} 0.287 1557828884718
openhab2_metric_number{name="LocalSun_EveningNightDuration"} UNDEF 1557828884718
openhab2_metric_number{name="Hs110Fridge_Rssi"} -40 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesMainBrushTime"} 258.0 1557828884718
openhab2_metric_number{name="ChromecastMiniMainbath_EpisodeNumber"} UNDEF 1557828884718
openhab2_metric_number{name="LocalSun_PositionElevation"} 54.46863800193032 1557828884718
openhab2_metric_number{name="LocalSun_NoonDuration"} 1 1557828884718
openhab2_metric_number{name="LocalSun_RadiationDirect"} 580.4890535278574 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_CleaningLastCleanError"} 0 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_StatusCleanTime"} 6 1557828884718
openhab2_metric_number{name="Hs110IndustrialLight_Rssi"} -56 1557828884718
openhab2_metric_number{name="PingableNetworkDevice_Latency_simon"} UNDEF 1557828884718
openhab2_metric_number{name="Hs110IndustrialLight_Power"} 0.0 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_StatusMapPresent"} 1 1557828884718
openhab2_metric_number{name="Hs110GlassCubeLight_Power"} 0.0 1557828884718
openhab2_metric_number{name="Hs110WashingMachine_Voltage"} 237.603566 1557828884718
openhab2_metric_number{name="Hs110GlassCubeLight_Voltage"} 239.433 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_NetworkRssi"} -23 1557828884718
openhab2_metric_number{name="SpotifyPlayerBridge_TrackNumber"} 0 1557828884718
openhab2_metric_number{name="LocalSun_CivilDawnDuration"} 43 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_HistoryTotalCleanArea"} 13450.325 1557828884718
openhab2_metric_number{name="Hs110WashingMachine_Current"} 0.030592 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesSideBrushTime"} 158.0 1557828884718
openhab2_metric_number{name="ChromecastAudiogroupAll_SeasonNumber"} UNDEF 1557828884718
openhab2_metric_number{name="LocalSun_PositionAzimuth"} 158.01577425730804 1557828884718
openhab2_metric_number{name="Hs110Catgenie_Voltage"} 237.649138 1557828884718
openhab2_metric_number{name="ChromecastAudiogroupAll_EpisodeNumber"} UNDEF 1557828884718
openhab2_metric_number{name="LocalSun_DaylightDuration"} 932 1557828884718
openhab2_metric_number{name="Hs110GlassCubeLight_EnergyUsage"} 0.015 1557828884718
openhab2_metric_number{name="Hs110WashingMachine_Rssi"} -57 1557828884718
openhab2_metric_number{name="LocalSun_RiseDuration"} 4 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_HistoryTotalCleanCount"} 511 1557828884718
openhab2_metric_number{name="Hs110IndustrialLight_Current"} 0.034 1557828884718
openhab2_metric_number{name="Hs110Catgenie_Current"} 0.017069 1557828884718
openhab2_metric_number{name="SpotifyPlayerBridge_TrackDiscNumber"} 0 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ActionsFan"} 60 1557828884718
openhab2_metric_number{name="LocalSun_AstroDawnDuration"} 95 1557828884718
openhab2_metric_number{name="LocalSun_SetDuration"} 4 1557828884718
openhab2_metric_number{name="Hs110IndustrialLight_Voltage"} 239.579 1557828884718
openhab2_metric_number{name="ChromecastUltraLounge_SeasonNumber"} UNDEF 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesSideBrushPercent"} 79 1557828884718
openhab2_metric_number{name="SpotifyPlayerBridge_TrackDurationMs"} 0 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_HistoryTotalCleanTime"} 16915 1557828884718
openhab2_metric_number{name="LocalSun_RadiationTotal"} 704.4435314883394 1557828884718
openhab2_metric_number{name="Hs110GlassCubeLight_Rssi"} -44 1557828884718
openhab2_metric_number{name="ChromecastMiniMainbath_TrackNumber"} UNDEF 1557828884718
openhab2_metric_number{name="Hs110Fridge_EnergyUsage"} 81.087 1557828884718
openhab2_metric_number{name="LocalSun_MorningNightDuration"} 113 1557828884718
openhab2_metric_number{name="Hs110WashingMachine_Power"} 0.0 1557828884718
openhab2_metric_number{name="Hs110Fridge_Power"} 0.0 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_CleaningLastCleanDuration"} 0 1557828884718
openhab2_metric_number{name="LocalSun_CivilDuskDuration"} 43 1557828884718
openhab2_metric_number{name="LocalSun_NauticDuskDuration"} 59 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_StatusInCleaning"} 0 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesSensorDirtTime"} 0.0 1557828884718
openhab2_metric_number{name="ChromecastMiniMainbath_SeasonNumber"} UNDEF 1557828884718
openhab2_metric_number{name="Hs110Catgenie_Power"} 1.653184 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_StatusCleanArea"} 2.9225 1557828884718
openhab2_metric_number{name="ChromecastUltraLounge_TrackNumber"} UNDEF 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_NetworkLife"} 30738 1557828884718
openhab2_metric_number{name="ChromecastAudiogroupAll_TrackNumber"} UNDEF 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesFilterPercent"} 34 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_StatusFanPower"} 60 1557828884718
openhab2_metric_number{name="LocalSun_AstroDuskDuration"} 95 1557828884718
openhab2_metric_number{name="Hs110Catgenie_Rssi"} -46 1557828884718
openhab2_metric_number{name="ChromecastMiniMainbath_DiscNumber"} UNDEF 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesFilterTime"} 51.0 1557828884718
openhab2_metric_number{name="ChromecastUltraLounge_EpisodeNumber"} UNDEF 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_StatusBattery"} 100 1557828884718
openhab2_metric_number{name="Hs110Catgenie_EnergyUsage"} 15.923 1557828884718
openhab2_metric_number{name="ChromecastUltraLounge_DiscNumber"} UNDEF 1557828884718
openhab2_metric_number{name="Tablet_Connected"} 1557828879096 1557828884718
openhab2_metric_number{name="SpotifyPlayerBridge_TrackProgressMs"} 0 1557828884718
openhab2_metric_number{name="Hs110Fridge_Voltage"} 238.068 1557828884718
openhab2_metric_number{name="Tablet_Battery_Level"} 100 1557828884718
openhab2_metric_number{name="LocalSun_NauticDawnDuration"} 59 1557828884718
openhab2_metric_number{name="LocalSun_NightDuration"} 99 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_CleaningLastCleanArea"} 0.0 1557828884718
openhab2_metric_number{name="ChromecastAudiogroupAll_DiscNumber"} UNDEF 1557828884718
openhab2_metric_number{name="XiaomiImagiSuck_ConsumablesSensorDirtPercent"} 0 1557828884718
openhab2_metric_number{name="Tablet_Brightness"} 38 1557828884718
# TYPE openhab2_metric_dimmer gauge
openhab2_metric_dimmer{name="DaylightCT"} 50.0 1557828884718
openhab2_metric_dimmer{name="PlexTVVolume"} 100 1557828884718
openhab2_metric_dimmer{name="SpotifyAllSpeakers_DeviceVolume"} 100 1557828884718
openhab2_metric_dimmer{name="Desklamp_ColorTemperature"} 50 1557828884718
openhab2_metric_dimmer{name="ChromecastAudiogroupAll_Volume"} 100 1557828884718
openhab2_metric_dimmer{name="LoungeOverhead_ColorTemperature"} 80 1557828884718
openhab2_metric_dimmer{name="ChromecastMiniMainbath_Volume"} 26 1557828884718
openhab2_metric_dimmer{name="KitchenOverhead_ColorTemperature"} 71 1557828884718
openhab2_metric_dimmer{name="SpotifyLoungeHifi_DeviceVolume"} 0 1557828884718
openhab2_metric_dimmer{name="SpotifyPlayerBridge_DeviceVolume"} UNDEF 1557828884718
openhab2_metric_dimmer{name="ChromecastUltraLounge_Volume"} 100 1557828884718
openhab2_metric_dimmer{name="ChromecastMiniLounge_Volume"} 30 1557828884718
openhab2_metric_dimmer{name="Dressingroom_ColorTemperature"} 63 1557828884718
openhab2_metric_dimmer{name="Dressingroom_Brightness"} 0 1557828884718
openhab2_metric_dimmer{name="PlexTVProgress"} 0 1557828884718
openhab2_metric_dimmer{name="SpotifyKitchenMini_DeviceVolume"} 100 1557828884718
openhab2_metric_dimmer{name="Desklamp_Brightness"} 0 1557828884718
# TYPE openhab2_metric_switch gauge
openhab2_metric_switch{name="ChromecastUltraLounge_Mute"} 0 1557828884718
openhab2_metric_switch{name="SpotifyLoungeHifi_DeviceShuffle"} 0 1557828884718
openhab2_metric_switch{name="Hs110Catgenie_Switch"} 1 1557828884718
openhab2_metric_switch{name="SpotifyKitchenMini_DeviceActive"} 0 1557828884718
openhab2_metric_switch{name="XiaomiImagiSuck_CleaningLastCleanFinish"} 0 1557828884718
openhab2_metric_switch{name="ChromecastAudiogroupAll_Idling"} 1 1557828884718
openhab2_metric_switch{name="EyeInTheSky_MotionAlarm"} 1 1557828884718
openhab2_metric_switch{name="SpotifyAllSpeakers_DeviceActive"} 0 1557828884718
openhab2_metric_switch{name="XiaomiImagiSuck_StatusDndEnabled"} 0 1557828884718
openhab2_metric_switch{name="EyeInTheSky_ExternalAlarmInput"} 0 1557828884718
openhab2_metric_switch{name="ChromecastAudiogroupAll_Mute"} 0 1557828884718
openhab2_metric_switch{name="SpotifyKitchenMini_DeviceShuffle"} 0 1557828884718
openhab2_metric_switch{name="Hs110IndustrialLight_Switch"} 0 1557828884718
openhab2_metric_switch{name="PlexTVStop"} 1 1557828884718
openhab2_metric_switch{name="Hs110WashingMachine_Switch"} 1 1557828884718
openhab2_metric_switch{name="SpotifyAllSpeakers_DeviceShuffle"} 0 1557828884718
openhab2_metric_switch{name="ChromecastUltraLounge_Idling"} 1 1557828884718
openhab2_metric_switch{name="SpotifyPlayerBridge_DeviceShuffle"} 0 1557828884718
openhab2_metric_switch{name="SpotifyKitchenMini_DeviceRestricted"} 1 1557828884718
openhab2_metric_switch{name="PlexTVPlay"} 0 1557828884718
openhab2_metric_switch{name="ChromecastMiniLounge_Mute"} 0 1557828884718
openhab2_metric_switch{name="ChromecastMiniLounge_Idling"} 1 1557828884718
openhab2_metric_switch{name="PingableNetworkDevice_Online_simon"} 0 1557828884718
openhab2_metric_switch{name="Hs110Fridge_Switch"} 1 1557828884718
openhab2_metric_switch{name="ChromecastMiniMainbath_Idling"} 1 1557828884718
openhab2_metric_switch{name="XiaomiImagiSuck_ActionsVacuum"} 0 1557828884718
openhab2_metric_switch{name="Hs110WashingMachine_Led"} 0 1557828884718
openhab2_metric_switch{name="ChromecastMiniMainbath_Mute"} 0 1557828884718
openhab2_metric_switch{name="Hs110Fridge_Led"} 1 1557828884718
openhab2_metric_switch{name="SpotifyAllSpeakers_DeviceRestricted"} 1 1557828884718
openhab2_metric_switch{name="SpotifyLoungeHifi_DeviceActive"} 0 1557828884718
openhab2_metric_switch{name="XiaomiImagiSuck_DndDndFunction"} 1 1557828884718
openhab2_metric_switch{name="Hs110GlassCubeLight_Led"} 1 1557828884718
openhab2_metric_switch{name="Bedroom1Lamp_Switch"} 0 1557828884718
openhab2_metric_switch{name="Hs110Catgenie_Led"} 1 1557828884718
openhab2_metric_switch{name="Hs110GlassCubeLight_Switch"} 0 1557828884718
openhab2_metric_switch{name="Hs110IndustrialLight_Led"} 1 1557828884718
openhab2_metric_switch{name="PlexTVPause"} 0 1557828884718
openhab2_metric_switch{name="SpotifyLoungeHifi_DeviceRestricted"} 1 1557828884718
# TYPE openhab2_metric_contact gauge
openhab2_metric_contact{name="Tablet_Battery_Charging"} 0 1557828884718
openhab2_metric_contact{name="Tablet_Battery_Low"} 1 1557828884718
openhab2_metric_contact{name="Tablet_Screen"} 0 1557828884718
3 Likes

(moved discussion about the UDEFs into the Issues Area of the GitHub repository)

Hello,
because the existing exporter didn’t suit my needs, i’ve written another one.
https://github.com/gfournetfayas/openhab2-exporter.git
Wrotten in Go, it follows the Prometheus standards.
It is based on the REST API of OpenHAB.
I’ll add stuff to the repo soon (service file for systemctl, grafana dashboard example).
All feedbacks are welcome !

Hello,

I’ve recently had a java heap problem on my openhab and I was looking for a way to monitor it. The great @rlkoshak pointed out this project and it looks very great.

Unfortunately, like others have mention, it doesn’t work on my openhab 2.4 (openhabian on raspberryPi 3)

I followed the instruction of @ricadelic but the problem is the installation of the .jar. For the three simpleclient*.jar, i’ve got no log and i didn’t find any trace of them in karaf (in feature or bundle). Then the last jar, for prometheus-metric give me this error:

2019-10-29 20:00:24.597 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/com.kuguhome.openhab.prometheusmetrics-2.4.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: com.kuguhome.openhab.prometheusmetrics [281]
  Unresolved requirement: Import-Package: io.swagger.annotations; version="1.5.7.SNAPSHOT"

	at org.eclipse.osgi.container.Module.start(Module.java:444) ~[?:?]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[?:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [10:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [10:org.apache.felix.fileinstall:3.6.4]

And when I try the web page it says:

{"error":{"message":"HTTP 404 Not Found","http-code":404,"exception":{"class":"javax.ws.rs.NotFoundException","message":"HTTP 404 Not Found","localized-message":"HTTP 404 Not Found"}}}

Is there something we can do about that bundle on 2.4?

1 Like

Hi all,

In 2.5.2 i got the same error as described above (New Add-on bundle for Prometheus health Metrics) . Has anyone managed to make the bunle compatible again?

just to update this great set of instructions:

the links to the dependencies appear to be broken. Here are some working links:

since “new users” are only allowed to improve this conversation with two links at a time, I have to split the post, sorry…

… continuing:

I also needed this package on openHAB 2.5.9 in Docker:

Installing this lead to a restart of HABmin/HABpanel but I noticed no changes so far.

The dependencies are quite outdated, is it possible to run more uptodate versions?

I got the Prometheus exporter running but it finally stopped working with OH3.
Fiddling with the really outdated dependencies I ended up doing a complete rewrite. Since there was already an initiative to add metrics to the openHAB core this resulted in two PRs (one to the OH core, one to introduce a new addon to provide the metric endpoint):

I got the whole chain running in a development build, see some resulting screenshots here:

If anyone is interested in testing this, I can provide you with dev builds of the OH distribution and the addon.

3 Likes

Here are the preview builds:

Unzip the distribution and place the metrics IO addon into the addons folder. (The addon will not work in the latest official Openhab release yet).

The metrics will then be available under /metrics/prometheus.
You’ll need to set up Prometheus and Grafana to have some charts, obviously :stuck_out_tongue:

Additional information and a sample Grafana dashboard is available in the Readme of the addon.

Please get back to me if you feel there is information missing so I can add it to the Readme.

Update
I documented a way to install this for existing installations (Openhabian) by replacing the core Monitor bundle and adding the new Metrics IO addon:

So no excuses anymore :stuck_out_tongue:
Have fun!

Original post

Here is another preview build of the addon where I included support for InfluxDB:
…removed the link due to a newer one being available…

I thought this might be especially interesting since the openhabian distro also includes an option to install Influx (but the openHAB core changes have to be released to openhabian for this to work).

1 Like

I guess that a standardized health/metrics API would make a lot of sense to take OH into a monitoring strategy. And from my feeling it should be part of the OH Core.

I’m not the expert here, but I saw some serious efforts with Karaf Decanter to become the Karaf Apaches way of monitoring.

Starting with Decanter 2.3.0 there is already a Prometheus appender included and starting with Karaf Decanter 2.7.0 there is also a Grafana/Loki appender available.

This is available in the current OH snapshot and documented here:

The link to the Grafana dashboard is broken due to an issue with the automatic documentation site creation but its available here:
https://raw.githubusercontent.com/openhab/openhab-addons/main/bundles/org.openhab.io.metrics/doc/dashboard.json