ualex73 / monitor_docker

Monitor Docker containers from Home Assistant
Apache License 2.0
301 stars 37 forks source link

Feature request to add disk usage #118

Closed erkr closed 7 months ago

erkr commented 1 year ago

Hi, I would love to have disk usage added to the monitored_conditions. Especially useful for database add ons like InfluxDB. I currently retrieve the size of the influx DB via an init command in The SSH & Web Terminal add-on: ‘ docker exec addon_a0d7b954_influxdb du -s /data/influxdb/data/homeassistant | mosquitto_pub -t …’ (For more info See: https://community.home-assistant.io/t/unreliable-influxdb-size-sensor/226871/49) So it would be great if similar disk usage sensors for particular folder (default root) inside the add ons could be created via this integration. Easier to set up and it would eliminate the need to publish them via MQTT

Best Eric

RoboMagus commented 1 year ago

This plugin exposes data that's available through interfaces such as docker container inspect .... Disk usage information is not information that is exposed.

You'd be better off creating a command_line sensor that basically does the same as what you're already doing now but skipping the MQTT workaround.

e.g.:

command_line:  
  - sensor:
      name: Influx DB size
      unique_id: influx_db_size
      unit_of_measurement: kB
      scan_interval: 300 # once every 5 minutes
      command: 'docker exec addon_a0d7b954_influxdb sh -c "du -sk Volumes/HomeAssistant/custom_components | cut -f1"'

This creates a native sensor in HomeAssistant with the size in kilobytes for the same Influx DB example you mentioned.

erkr commented 1 year ago

Thanks, that is indeed a feasible option. Thanks for the example!

RoboMagus commented 1 year ago

Happy to help. After posting that sensor config I found out that depending on system load and directory size the time required to execute the command may exceed the default timeout. For that you may wish to increase the timeout if you run into that.