Unreliable InfluxDB size sensor

I finally decided to

  1. create my InfluxDB database sensors by
  2. relying on the folder size instead of the _internal DBs shard series field “diskBytes” as it is hilarious small compared to the actual folder size (approx. 56 times smaller) and therefore
  3. to use a more basic approach by using a simple command_line sensor. That one looks like
  - platform: command_line
    name: InfluxDB size (homeassistant)
    scan_interval: 120 # Change to higher value after finishing tests
    command_timeout: 30
    command: "docker exec addon_XXXXXXXX_influxdb du -shm /data/influxdb/data/homeassistant | cut -f1"
    unit_of_measurement: MB
    value_template: "{{ value }}"

I reloaded command line entities (did not restart HA) and it has been created.
BUT: it shows a size of zero (0 MB)

grafik

The command itself is working perfectly when fired on the SSH console. What did I miss?

Update 1:
I´m pretty sure I found the root cause thinking bout it for 10 seconds. The command is performed from homeassistant so from inside the homeassistant container (I´m running HASS OS too). And there even is no docker command inside “homeassistant”. So any way to run that command for the command line sensor with “root privileges” (how to break out of the HA docker container?)? I´m pretty sure that´s impossible.

Running it from root ssh, storing it in a text file and reading that one from homeassistant as sensor now sounds pretty cool to me (not that much overkill)… would still like to avoid this, hopefully there´s a smarter solution.

Man I liked to keep it simple so much… what is the next approach without pushing it as far as @tom_l :slight_smile: ?

Update 2:
My last approach was a “hammer style” one: using SSH to login to the host and get the information. Unfortunately this comes with several detailled and overall security risks like

  1. by either passing the SSH password for the HA host on the command line sensor or
  2. the need to whitelist the HA container in the host known_hosts file (password-less SSH),
  3. in the end the biggest security issue would be HA container being able to access the host - which is a nice “Welcome! Get in!” for every bad guy, especially when having HA publicly accessable on the internet…
    In my opinition homeassistant container should not have the opportunity to get access to the host. So providing the information from the host for the homeassistant container is also complicated but quite good in terms of security.

Not sure how to proceed… :woozy_face:

1 Like