For network in and network out you need to provide the name of the interface to monitor. See the docs for an example.
Exactly, the update now requires some type
elements to also have arg
. On my NUC I use:
- type: throughput_network_in
arg: eno1
- type: throughput_network_out
arg: eno1
Docs updated above show which are now required.
Can’t get it to work sensor.core
says unavailable
. This is what shows up in the log, every 30 seconds (polling time)
2020-10-11 21:42:52 WARNING (SyncWorker_27) [homeassistant.components.rest.sensor] Empty reply found when expecting JSON data
This is the config under sensor:
It’s basically a copy/paste of the first post config text but with my own internal IP (http i working) and replaced llt by respapi which is defined in secret.yaml with the corresponding long lived token.
- platform: rest
resource: http://192.168.2.84:8123/api/hassio/core/stats
name: core
unit_of_measurement: '%'
value_template: '{{ value_json.data.cpu_percent }}'
scan_interval: 30
headers:
Authorization: !secret restapi
Content-Type: application/json
json_attributes_path: "$.data"
json_attributes:
- memory_percent
- platform: rest
resource: http://192.168.2.84:8123/api/hassio/supervisor/stats
name: supervisor
unit_of_measurement: '%'
value_template: '{{ value_json.data.cpu_percent }}'
scan_interval: 30
headers:
Authorization: !secret restapi
Content-Type: application/json
json_attributes_path: "$.data"
json_attributes:
- memory_percent
- platform: template
sensors:
core_mem:
friendly_name: Core Memory Usage
unit_of_measurement: '%'
value_template: "{{ state_attr('sensor.core', 'memory_percent') }}"
- platform: template
sensors:
supervisor_mem:
friendly_name: Supervisor Memory Usage
unit_of_measurement: '%'
value_template: "{{ state_attr('sensor.supervisor', 'memory_percent') }}"
Don’t know what I’m doing wrong.
Does your token secret have this form?
"Bearer eyJ0eXAiOiJKV1QiLCJhSUPERLONgTOKENlZWQ0NzBhYLe8sxN8nup1Uw"
i.e. does it have the word “Bearer” in front of the token?
Ok, one more addition to this thread. After seeing another post (sorry I lost it and can’t link it) I discovered that you can pull the same usage information for each of your addons.
Example for my unifi controller addon.
- platform: rest
resource: http://192.168.1.24:8123/api/hassio/addons/a0d7b954_unifi/stats
name: unifi
unit_of_measurement: '%'
value_template: '{{ value_json.data.cpu_percent }}'
scan_interval: 30
headers:
Authorization: !secret restapi
Content-Type: application/json
json_attributes_path: "$.data"
json_attributes:
- memory_percent
The output of this api endpoint is the same as the core and supervisor.
{
"result": "ok",
"data":{
"cpu_percent": 0.52,
"memory_usage": 639205376,
"memory_limit": 3133292544,
"memory_percent": 20.4,
"network_rx": 278650723,
"network_tx": 1107050279,
"blk_read": 149344256,
"blk_write": 289079296
}
}
YES!
I have been chasing down an intermittent (but prolonged - requiring a restart to stop) high core CPU use for weeks. Profiler and py-spy have failed to reveal the culprit. So my next option was going to be disabling addons one by one.
I’ll implement these sensors instead and see if that helps track the issue down. Thank you.
EDIT: haven’t seen one of these for a while:
All appears to be working though:
Well that was a dead end. Though I am beginning to suspect something is amiss with the api call for the core cpu %. This:
- platform: rest
resource: https://mydomain_redacted.duckdns.org/api/hassio/core/stats
name: Core CPU
unit_of_measurement: '%'
value_template: '{{ value_json.data.cpu_percent }}'
scan_interval: 30
headers:
Authorization: !secret ha_api_token
Content-Type: application/json
json_attributes_path: "$.data"
json_attributes:
- memory_percent
Is currently showing:
And as you can see from the graph it has been growing steadily up.
However, monitoring the same statistic in the supervisor it never gets above 7%:
EDIT: I just saw the supervisor core cpu monitor hit 98%, very briefly - about the same time as the api sensor updated. Is the cpu API call causing the cpu use to skyrocket?
Why does restarting home assistant stop this happening?
EDIT2: in case this is caused by multiple api calls happening at once I have updated my rest sensors to use different prime number scan intervals, from 23 to 71 seconds.
One more update. After speaking with Ludeeus on Discord, rather than use the external API access like:
resource: https://mydomain_redacted.duckdns.org/api/hassio/core/stats
If you use internal access to the API this considerably reduces the overhead. As I use duckDNS and its security certs I have to use https and so accessing
resource: http://supervisor/core/stats
will not work for me. If you can access home assistant locally via http use that resource. However if you use TLS certs directly in home assistant you can can get around this by using a command line sensor instead:
- platform: command_line
name: Core CPU
command: 'curl -sSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/core/stats'
unit_of_measurement: '%'
value_template: "{{ (value_json.data.cpu_percent|float/4)|round(2) }}"
scan_interval: 60
json_attributes:
- data
- platform: command_line
name: Supervisor CPU
command: 'curl -sSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/supervisor/stats'
unit_of_measurement: '%'
value_template: "{{ (value_json.data.cpu_percent|float/4)|round(2) }}"
scan_interval: 60
json_attributes:
- data
- platform: template
sensors:
core_memory:
friendly_name: "Core RAM"
value_template: "{{ (state_attr('sensor.core_cpu', 'data')|to_json|from_json).memory_percent }}"
unit_of_measurement: '%'
supervisor_memory:
friendly_name: "Supervisor RAM"
value_template: "{{ (state_attr('sensor.supervisor_cpu', 'data')|to_json|from_json).memory_percent }}"
unit_of_measurement: '%'
Note that as I am using a four thread CPU the percent CPU value has to be divided by 4. Adjust the template for your hardware.
Finally an addon example for completeness:
- platform: command_line
name: Grafana CPU
command: 'curl -sSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/addons/a0d7b954_grafana/stats'
unit_of_measurement: '%'
value_template: "{{ (value_json.data.cpu_percent|float/4)|round(2) }}"
scan_interval: 60
json_attributes:
- data
- platform: template
sensors:
grafana_memory:
friendly_name: "Grafana RAM"
value_template: "{{ (state_attr('sensor.grafana_cpu', 'data')|to_json|from_json).memory_percent }}"
unit_of_measurement: '%'
This has considerably reduced the CPU % when
as I am on Homeassistant OS and always use the !secret for the bearer token, please le me ask where your token is stored when you use "Authorization: Bearer $SUPERVISOR_TOKEN"
?
or in other words, can I rewrite this:
- platform: rest
name: Hassio Rpi4 config
resource: !secret resource_hassio_rpi4_config
value_template: > #components|list|count}}
{{value_json.version}}
json_attributes:
- components
- unit_system
- config_dir
headers:
Content-Type: application/json
Authorization: !secret api_bearer_token
User-Agent: Home Assistant REST sensor
scan_interval: 3600
to the sensors you use with the ‘http://supervisor/core/stats’ as resource?
$SUPERVISOR_TOKEN
is like a system variable. No need to define a token! Just use that template verbatim. I don’t know if it can be used in the rest Authorisation option though. I suspect not.
finally! with that info I could use this thread Update notifications! Core, HACS, Supervisor and Addons and the sensor:
- platform: command_line
name: Supervisor updates
command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $SUPERVISOR_TOKEN" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version,"addons":[.data.addons[] | select(.version != .installed)]}'''
value_template: >
{{value_json.addons|length}}
json_attributes:
- newest_version
- current_version
- addons
to pull all info from supervisor I was looking for. Only thing is:
None od my add-ons seem to be there… I noticed something this morning already when installing the Portainer, and all it could find was the hassio_observer
where have they all gone?!?
The home assistant containers are hidden by default. Read the portainer addon docs, it tells you how to un-hide them. I’d tell you but it’s ages since I did it and I’ve forgotten.
ok I will, but is that the same reason they don’t show up in the sensor?
No, probably not. Just a sec. Let me check my addon sensor.
EDIT: I don’t see any addons listed either. I think that attribute only shows addons with updates available.
ok thanks.
as for the Portainer if you have time… I did find the hidden containers, but can only Remove them
and the Add-ons are listed as Images:
They are not the containers. They are the instructions to hide the containers.
Access to these containers can be gained by going into Portainer → Settings → Hidden containers. Then delete the listed hidden labels (io.hass.type labels). Only do this if you know what you’re doing!
Tom,
Why are you dividing by 4? That sensor tells you how much CPU is used by supervisor. Why does the number of cores matter?
Also I have similar for all addons etc… check my system monitor package in my repo.
Because the report returns the sum of all cores.
Ok but if supervisor is telling you CPU percentage then can that not be spread over 4 cores?