I’m using docker Monitor:
this is failing for me can I can how you configured it?
Try this
homeassistant:
customize:
package.node_anchors:
settings: &settings
switch: true
sensors:
- status
- uptime
- image
- cpu_percentage_usage
- memory_usage
- memory_percentage_usage
- network_total_up
- network_total_down
docker_monitor:
hosts:
- url: tcp://192.168.1.61:2375
name: vmTBSH01
event: false
containers:
duplicati:
<<: *settings
Are you also running Home Assistant in a container?
If so, you need to give access to the socket. Add the following volume to your home assistant container:
-v /var/run/docker.sock:/var/run/docker.sock
I just use bash scripts to return docker stats in JSON format and use command line sensors to get them into HA myself, less fuss for me.
Are you able to share some of your scripts and sensors as I’m struggling with the docker monitor component?
I recently reworked them into MQTT sensors, basicly it’s dumping docker stats
into MQTT sensors and i pull them from there.
Would still appreciate anything you can share as I’m stuck on getting this to work?
Sure thing first off I have bash scripts on my docker hosts:
#!/bin/bash
mqttbroker=[redacted]
mqttuser=[redacted]
mqttpwd=[redacted]
data=`docker stats --no-stream --format '"{{.Name}}": {{json .}},'`
data=${data%?}
data=`echo \{ ${data} \} | jq '.'`
for row in $(echo $data | jq '.[].Name'); do
text=$(echo $data | jq ".$row" | tr -d %)
state=$(echo "{\"value\": \"Ok\"}" | jq '.')
container=$(echo $row | tr -d \")
mosquitto_pub -h $mqttbroker -u $mqttuser -P $mqttpwd -t docker/$container/state -m "$state" -r
mosquitto_pub -h $mqttbroker -u $mqttuser -P $mqttpwd -t docker/$container/attributes -m "$text" -r
done
# echo $data
Then I have an automation fire off:
- alias: Update Docker Stats
trigger:
- platform: homeassistant
event: start
- platform: time_pattern
seconds: '/30'
action:
- service: shell_command.update_dh2
- service: shell_command.update_dh
Those shell commands are here:
(note: I use ssh keys so passwords are not needed to execute remote commands)
update_dh2: 'ssh root@[redacted] /root/docker_stats.sh'
update_dh: 'ssh root@[redacted] /root/docker_stats.sh'
Then my MQTT sensors:
# Docker MQTT Sensors
- platform: mqtt
name: docker_zoneminder
state_topic: "docker/zoneminder3/state"
json_attributes_topic: "docker/zoneminder3/attributes"
value_template: "{{ value_json.value }}"
- platform: mqtt
name: docker_mariadb
state_topic: "docker/mariadb/state"
json_attributes_topic: "docker/mariadb/attributes"
value_template: "{{ value_json.value }}"
- platform: mqtt
name: docker_portainer
state_topic: "docker/portainer/state"
json_attributes_topic: "docker/portainer/attributes"
value_template: "{{ value_json.value }}"
I have them display like so:
First the decluttering card bit:
decluttering_templates:
docker_entity_template:
card:
entities:
- entity: '[[entity]]'
icon: 'mdi:server'
name: Status
- attribute: NetIO
entity: '[[entity]]'
icon: 'mdi:ethernet'
name: Network In/Out
type: attribute
- attribute: MemUsage
entity: '[[entity]]'
icon: 'mdi:memory'
name: Memory Usage
type: attribute
- entities:
- attribute: CPUPerc
decimal: '2'
entity: '[[entity]]'
height: 25px
icon: 'mdi:cpu-64-bit'
max: '100'
min: '0'
name: CPU Usage
severity:
- color: var(--label-badge-green)
from: '0'
to: '40'
- color: orange
from: '40'
to: '65'
- color: var(--label-badge-red)
from: '65'
to: '100'
unit_of_measurement: '%'
entity_row: true
style: |-
bar-card-name {
font-weight: bold;
text-shadow: 2px 2px 2px black;
}
bar-card-value {
font-weight: bold;
text-shadow: 2px 2px 2px black;
}
animation:
state: 'on'
type: 'custom:bar-card'
- entities:
- attribute: MemPerc
decimal: '2'
entity: '[[entity]]'
height: 25px
icon: 'mdi:memory'
max: '100'
min: '0'
name: Memory Used
severity:
- color: var(--label-badge-green)
from: '0'
to: '40'
- color: orange
from: '40'
to: '65'
- color: var(--label-badge-red)
from: '65'
to: '100'
unit_of_measurement: '%'
entity_row: true
style: |-
bar-card-name {
font-weight: bold;
text-shadow: 2px 2px 2px black;
}
bar-card-value {
font-weight: bold;
text-shadow: 2px 2px 2px black;
}
animation:
state: 'on'
type: 'custom:bar-card'
title: '[[name]]'
type: entities
And now the actual card:
template: docker_entity_template
type: 'custom:decluttering-card'
variables:
- entity: sensor.docker_zoneminder
- name: ZoneMinder
rinse and repeat the cards.
This is amazing, thanks so much!
Just a side note, the usage of mqtt over using the REST API in HA was due to future planning on moving my venv setup to a docker instance that way I don’t have to modify the bash scripts.
Maybe a silly question but why do you have two shell commands? dh and dh2?
2 servers running docker
@klogg do you mind sharing how you build your supervisor_updates sensor?
Would be interested! Thanks
There is a whole thread on this here so it is not my own work and there is a lot more there than I use. I suggest you take a look
#============
#=== Sensors
#============
sensor:
# Sensor to track available updates for supervisor & addons
- platform: command_line
name: Supervisor updates
command: 'curl http://supervisor/supervisor/info -H "Authorization: Bearer $(printenv 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
# Sensors to track updates to other core components (audio, dns and CLI)
- platform: command_line
name: Updater Audio
command: 'curl http://supervisor/audio/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version}'''
value_template: "{% if value_json.newest_version != value_json.current_version %}on{% else %}off{% endif %}"
json_attributes:
- newest_version
- current_version
- platform: command_line
name: Updater DNS
command: 'curl http://supervisor/dns/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version}'''
value_template: "{% if value_json.newest_version != value_json.current_version %}on{% else %}off{% endif %}"
json_attributes:
- newest_version
- current_version
- platform: command_line
name: Updater CLI
command: 'curl http://supervisor/cli/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version}'''
value_template: "{% if value_json.newest_version != value_json.current_version %}on{% else %}off{% endif %}"
json_attributes:
- newest_version
- current_version
# Alternate updater sensor for core since binary_sensor.updater is very slow to recognize updates
- platform: command_line
name: Updater Core
command: 'curl http://supervisor/core/info -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" | jq ''{"newest_version":.data.version_latest,"current_version":.data.version}'''
value_template: "{% if value_json.newest_version != value_json.current_version %}on{% else %}off{% endif %}"
json_attributes:
- newest_version
- current_version
#===================
#=== Binary Sensors
#===================
binary_sensor:
- platform: template
sensors:
# True if there's an update available for supervisor
updater_supervisor:
friendly_name: 'Updater - Supervisor'
device_class: problem
entity_id:
- sensor.supervisor_updates
value_template: "{{ state_attr('sensor.supervisor_updates', 'current_version') != state_attr('sensor.supervisor_updates', 'newest_version') }}"
availability_template: "{{ (states('sensor.supervisor_updates') | int(-1)) > -1 }}"
# True if there's updates available for any HACS components
updater_hacs:
friendly_name: 'Updater - HACS'
device_class: problem
entity_id:
- sensor.hacs
value_template: "{{ states('sensor.hacs') | int > 0 }}"
# True if there's updates available for any addons
updater_addons:
friendly_name: 'Updater - Addons'
device_class: problem
entity_id:
- sensor.supervisor_updates
value_template: "{{ states('sensor.supervisor_updates') | int > 0 }}"
implementado, obrigado !
@klogg
Nice work.
Is it possible to strip the
pending update(s)
from the result or how can I translate it to my native language?
Thanks for sharing your work
It’s hard coded in the sensor I’m afraid, I didn’t put it there.
You could create a custom button to mimic the entity line and then configure it yourself.
Or even easier of course, a template sensor.
Okay I’ll try it with a template.
I’ve one other question and hope some one can help me to create a version sensor for synology DSM
I found the following from the command line:
more /etc.defaults/VERSION
Which results in:
majorversion="6"
minorversion="2"
productversion="6.2.3"
buildphase="GM"
buildnumber="25426"
smallfixnumber="0"
builddate="2020/05/12"
buildtime="06:20:24"
Which translates to:
DSM 6.2.3-25426 update 0