Metrics Addon Not Providing Items Metrics

I’m using openHab 5.1.1, Zwave devices, and just installed the Metrics addon. When I access /rest/metrics/prometheus, I do see metrics, however, the items are missing their “values”. For example, I have a several outlets that report state (on/off), watts, and amps. I also have some dimmer switches that report their percentage brightness.

None of these values are showing up in the metrics. The documentation says there is no configuration to the Metrics addon.

How do I get the states/values of all my devices into the metrics output for scraping?

Based on the docs for the Metrics add-on you don’t. Item states are not among the data that it reports.

The docs state:

Currently the following metrics are provided:

  • openHAB events counts (per topic)
  • openHAB bundle states
  • openHAB thing states
  • openHAB rule runs (per rule)
  • openHAB threadpool stats (per scheduler)
  • JVM stats including metrics of
    • class loader
    • memory
    • GarbageCollector
    • OS (system load, CPU)
    • thread metrics

You should be able to see how many events occur on an Item by Item basis but this add-on doesn’t report the actual events.

If you want access to the actual events, there is a websocket (if I recall correctly) you can subscribe to. Or you can pull the items from the /rest/items GET endpoint which will include the state of the Item at that time.

My understanding of this plug-in though is to export information to monitor the performance of openHAB as a system, not to replicate it’s internal states. So I wouldn’t expect it to report Items states.

I did read this in the documentation, and I interpreted it as “states of all the things in openHAB” which would include all my zwave items, since they are things in openHAB.

I don’t want to access events, I want to access the data of all my things (ie: voltage of wall plugs, temperature from motion sensor, etc) so I can graph them.

“Thing” is a term of art in OH. A Thing is not an Item. I follow the convention of always capitalizing these terms when using them, but that’s not a universal convention.

“The states of things” in this case is the ONLINE/OFFLINE/COMMUNICATION ERROR/etc state of Things (MainUI → Settings → Things). This is not related to Items and their states.

Then use a database supported by Graphana (or what ever you are wanting to chart), e.g. InfluxDB, and set up the corresponding persistence add-on in openHAB. Configure it to save the states of the Items based on what ever strategy you choose. Then you can chart the states of the Items over time straight from the database.

Or use openHAB itself. All of the UIs for OH support charting the states of Items over time. The first run wizard would have had you install rrd4j so you might already be saving all the numeric states of all your Items already which will be available for OH to use in charts.

I did, but it never worked properly with openHab (see next)

I did. I created an “every minute”, “every 5 minute”, and “every change” strategies. This never seemed to do anything.

Persistence was stored in Influx, but I could never get historical item data/states into influx.

True, but it’s only single graphs per item. No way to create a graph for all temp monitors, or all door sensors, etc. Which is why I set up influx, and grafana, but could never get item data into influx.

I was hoping this new Metrics plugin would fix these issues, but seems to have the same restrictions.

This plugin looks promising to do what I need, and I hope the devs are considering the open pull-request to merge it (though development looks stalled):

It’s not enough to create the strategies. You have to apply them to the Items.

Add Configuration → Select the Items to persist → select the strategies to use

It’s the configuration that applies the strategies, filters, etc to specific Items (or all Items, or members of chosen Groups).

This doesn’t make much sense to me. Persistence is the historical states.

???

And I didn’t even have to do anything to get that chart. I configured the semantic model and just clicked on “Analyze All” on the Temperature card on the Properties tab. I could even further customize that by adding or removing Items and saving it and I can add it to a page or treat the chart as a page all by itself.

HABPanel has a similar charting capability though it’s more configuration work up front to get it working.

It’s been years since I used sitemaps but I do remember even there I could chart more than one Item at a time. I think you passed it a Group and it would chart all it’s members.

You don’t need a new plugin. You need to figure out how to do this with what OH already provides.

I can’t find that screenshot anywhere in the UI. When I click Settings → Items → Office Outlet (Amps), there’s nothing on this page about adding config, or strategies.

Also, the docs don’t talk about this UI functionality, everything in the docs is via text files which I have this:

$ cat /opt/openhab/conf/persistence/influxdb.persist
Strategies {
  everyMinute   : "0 * * * * ?"
  every5Minutes : "0 0/5 * ? * * *"
  everyHour     : "0 0 * * * ?"
  everyDay      : "0 0 0 * * ?"
  default = everyUpdate
}

Filters {
  fiveSeconds : T 5 s
  thirtySeconds : T 30 s
}

Items {
//  * : strategy = everyUpdate

  Playroom_Outlet_Watts, Playroom_Outlet_2_Electric_meter_amps : strategy = everyUpdate filter = fiveSeconds

  Outside_Monitor_Sensor_temperature, LivingroomLights_Dimmer, PlayroomLights_Switch : strategy = everyMinute

  Doors_Group*, TrippLiteUPS_Group*, TrippLite_UPS_Group* : strategy = everyMinute

  Temperature*, Weather* : strategy = everyHour
}

Does that not “apply” the config?

You said above that states are different from values. Persistence/influx would sometimes (not all the time) store if a light switch turned on, or off, but would never store the amps/watts, or temperature. On/off is a state, amps/watts are values.

That graph looks lovely; In 3 years using OH I’ve never been able to come anywhere close to that. I might get 1 data point every other week or so when a light turned on.

Well, after reading the docs multiple times, and spending who-knows-how-many-hours messing with it, I still can’t get it to work. The docs need some screenshots, and a bit more HOWTO for these seemingly simple things. Most of the docs still talk about config files on disk. :confused:

MainUI → Settings → Persistence

But the ability to configure persistence through the UI is relatively new, so the docs are not so great.

It’s been a long time since I’ve dealth with .persist files, so I can’t comment much on that specific file. Do you see errors in the logs when OH tries to load that file?

Note, as of OH 5.1 the following line will throw an error:

default = everyUpdate

There is no longer such a thing as a “default” strategy. It appears there are lots of examples still in the docs that need to be updated to remove that.

No, I said Things are different from Items and a Thing’s state is different from an Item’s state. The metric add-on will report Thing’s states, but not Item’s states. Persistence is supposed to be used for Item states. So let’s focus on why that’s not working.

Are these amps/watts represented by any of the Items in that .persist config? Obviously Playroom_Outlet_Watts does but if you are expecting other Items to be persisted too they are not among those you’ve configured.

My persistence config is super simple. The code tab in the UI is

configurations:
  - items:
      - "*"
    strategies:
      - everyMinute
      - everyChange
    filters: []
aliases: {}
cronStrategies:
  - name: everyMinute
    cronExpression: 0 */1 * * * ?
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

Which would be the following in a .persist file:

Strategies {
  everyMinute   : "0 * * * * ?"
}


Items {
  * : strategy = everyChange, everyMinute
}

This is rrd4j so everyMinute is required.

And I confiugured my semantic model:

Which populates the Overview tabs.

To bring up the chart above all I did was click on “Temperature” and then “Analyze All”

That’s it. A Persistence config to save all Items on everyChange and once a minute (because I’m using RRD4j) and some effort setting up the semantic model. I didn’t need to do anything complicated or special. Based on this .persist file I’d say you are making it overly complicated to start with.

Maybe start with something simple like that and grow from there as needed.

Which are still supported too. But indeed the docs need some volunteers to update in lots of areas. In a 100% volunteer project like this, the docs are often the last to get updated.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.