home-assistant/core

Prometheus metric is not updated with actual value

neothematrix opened this issue · 4 comments

The problem

hello!
I noticed that there is a specific metric that is always exported by prometheus with a value of "0.0" despite the actual value shown by the same metric on Home Assistant.

The metric is the "health index", gathered by the "Netatmo" integration, here's the example metric exposed by Prometheus, I put only one row but different samples on different times are always reporting a value of "0.0".

homeassistant_sensor_enum_None{domain="sensor",entity="sensor.myhome_health",friendly_name="Myhome Health index"} 0.0

and here's the detailed export of the entity as shown by home assistant:

entity_id,state,last_changed
sensor.myhome_health,fair,2024-10-16T22:00:00.000Z
sensor.myhome_health,fine,2024-10-17T08:11:50.020Z
sensor.myhome_health,healthy,2024-10-17T15:58:51.137Z
sensor.myhome_health,fine,2024-10-17T17:43:50.535Z
sensor.myhome_health,fair,2024-10-17T23:13:52.776Z
sensor.myhome_health,fine,2024-10-18T07:12:53.112Z

Could it be an issue of conversion between the metric output that is string? I don't know how to further debug or if I can do anything to fix it, so any help would be appreciated!

thanks!

What version of Home Assistant Core has the issue?

core-2024.10.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

prometheus

Link to integration documentation on our website

https://www.home-assistant.io/integrations/prometheus

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

Hey there @knyar, mind taking a look at this issue as it has been labeled with an integration (prometheus) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of prometheus can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign prometheus Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


prometheus documentation
prometheus source
(message by IssueLinks)

Hey there @cgtobi, mind taking a look at this issue as it has been labeled with an integration (netatmo) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of netatmo can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign netatmo Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


netatmo documentation
netatmo source
(message by IssueLinks)

knyar commented

The issue here is on the prometheus integration side, which is trying really hard to export metrics for as many entities as possible. The state values of the health index sensor currently are not supported by the state_as_number helper, and at the moment the integration exports state of such sensors as zero.

I think there are two improvements we can make here:

  1. Stop showing metrics that are incorrect - specifically, avoid creating metrics with zero values for entities that have state which cannot be converted to a number. I had a PR open that addressed it only for some sensors, which I've just expanded to be more generic: #127262 (would appreciate a review)
  2. Implement exporting of sensors of SensorDeviceClass.ENUM in a same way as we implement other enums (e.g. HVAC modes and actions). This will cover Netatmo's health index as well as other sensors of ENUM class.

I will be happy to review the PR if someone wants to take a stab at the second one.