How to access core and supervisor CPU + MEM usage (HA OS)

I want to have those 4 numbers as sensors:

  • Those are from the former, now “hidden system management” page /hassio/system.
  • Less important: number 5, which is available e. g. via System Monitor - Home Assistant.
    Interesting: the disk usage of this sensor.disk_use_percent (from system monitor) with 67.9 % differs from the one shown as 5 in the screen.

So: how to get CPU + MEM usage of HA Core and HA Supervisor?

Glances - Home Assistant unfortunately does not provide that information (only total cpu/mem of all docker containers) and - obviously - needs to run the Glances addon. And there’s no Portainer integration unfortunately, that would be one way in theory.

Preferred looking at a solution

  1. as “stock” / “out of the box” (low effort, no additional integrations/addons needed) as possible
  2. avoiding the use of GitHub - ualex73/monitor_docker: Monitor Docker containers from Home Assistant or other custom integrations from HACS
  3. avoiding command_line sensors (except if it’s the only option, well…)

Ideas / working proofs welcome :slight_smile:

Core stats and supervisor stats.

Use a rest or restful sensor.

I haven’t tried.

Nice, thanks :+1: Never used one before. If someone has a working yaml snippet containing the authentication part for the supervisor… thanks for sharing.

I made a couple posts about them recently.

Post two

Although you might actually want a restful sensor if you want more than one thing from each endpoint

1 Like

Still no progress on this.

I found the information needed to be in

  • Core CPU: /core/stats as data.cpu_percent
  • Core MEM: /core/stats as data.memory_percent
  • Supervisor CPU: /supervisor/stats as data.cpu_percent
  • Supervisor MEM: /supervisor/stats as data.memory_percent

I’d prefer to use a RestFUL sensor, but even more complicated than a REST sensor.

For the REST sensor:
Are they “hot reloadable” from /developer-tools/yaml? Or is a HA Core restart required?

I really wish this would just be in the Supervisor integration out of the box as it is for other addons too.

I went with a old-school command_line sensor (I basically try to avoid using them meanwhile but the struggle with the REST or RESTful sensors is even worse).

Unfortunately, after initial load of the CL sensors, the value never gets updated, so the scan_interval is not respected. E. g.:

  - platform: command_line
    name: Home Assistant Core CPU percent
    unique_id: vs-code-generated
    scan_interval: 30
    command_timeout: 60
    command: 'curl http://supervisor/core/stats -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"cpu_percent":.data.cpu_percent}'''
    value_template: "{{ value_json.cpu_percent }}"
    unit_of_measurement: "%"

The changes visuable are from reloading CL sensors:

Any idea on this e. g. @ master of CL sensors @CentralCommand ?


Meanwhile TBH I am so bugged :frowning_face: that I’m just ten minutes away of writing a feature request (knowing it will either not get realized or only in many months) for the Supervisor integration. The data is already there, why not exposing it for Core and Supervisor as done for all the other addons?


Update:

Is it possible that scan_interval for CL sensors has been disabled/ignored a long time ago already? Because:

  • I probably have few other CL sensors which never update (only on manual reload and HA start)
  • Using the homeassistant.update_entity service triggers the CL sensor update just fine.

Update: since HA Core 2023.4 CPU + MEM of HA Core and HA Supervisor are finally available natively via the supervisor integration:

The Supervisor integration now provides sensors containing the Home Assistant Core and Supervisor’s stats. Thanks, @ludeeus!

BUT: once I switched to those,
a) My CPU usage went up quite significantly (approx. 10 %) plus
b) I find massive log entries of those:

2023-11-07 17:57:11.148 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_cpu_percent is taking over 10 seconds
2023-11-07 17:58:11.568 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_cpu_percent is taking over 10 seconds
2023-11-07 17:59:10.912 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_cpu_percent is taking over 10 seconds
2023-11-07 18:00:19.941 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_cpu_percent is taking over 10 seconds
2023-11-07 18:01:11.090 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_cpu_percent is taking over 10 seconds
2023-11-07 18:02:11.063 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_cpu_percent is taking over 10 seconds

What’s wrong with this supervisor integration for the sensor.home_assistant_core_cpu_percent sensor?
Will disable it and see if CPU usage wents down again, but even when it does: that’d be a proof, not a solution…

Here’s the proof: once I enabled those supervisor integration powered sensors, overall system CPU usage increased:


Edit: once sensor.home_assistant_core_cpu_percent entity has been disabled, HA log gives these:

2023-11-07 18:20:10.803 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_cpu_percent is taking over 10 seconds
2023-11-07 18:21:00.823 WARNING (MainThread) [homeassistant.helpers.entity_component] Forced update failed. Entity sensor.home_assistant_core_cpu_percent not found.
2023-11-07 18:21:10.929 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.home_assistant_core_memory_percent is taking over 10 seconds
2023-11-07 18:22:01.018 WARNING (MainThread) [homeassistant.helpers.entity_component] Forced update failed. Entity sensor.home_assistant_core_cpu_percent not found.

Totally crazy. What “forced update”? It has been disabled…


Edit 2:
Earlier I updated the command line based sensors (4: CPU + MEM of Core + Supervisor) with an automation:

# TRIGGER:
platform: time_pattern
id: command_line_sensors
minutes: /1
...
# ACTION:
service: homeassistant.update_entity
data: {}
target:
  entity_id:
    - sensor.home_assistant_core_cpu_percent
    - sensor.home_assistant_core_memory_percent
    - sensor.home_assistant_supervisor_cpu_percent
    - sensor.home_assistant_supervisor_memory_percent

That was the cause for the new “forced update” log entries. Once I disabled that action in the automation (event 2 in timeline), overall CPU usage went down to a normal average. Disabling the Core CPU sensor (event 1) changed nothing, so did re-enabling it (event 3). HA log entries (... is taking over 10 seconds) are gone too for now.

Will monitor it for a while as it’s just been a few minutes. Curious why entities which are automatically updated (in this case by the supervisor integration) can create such an issue when at the same time requested to update using the homeassistant.update_entity service. Probably a performance/timing thing, which resulted in the spammed HA log entries.


Final notice few hours later: seems to be fixed indeed.

Summary: this whole experience once again acts as a prove how important it is to monitor what’s going on on the system. This way one can even discover when the monitoring tools themself go crazy :slight_smile: …and fix it. No monitoring, system running way worse.