So, I don’t use influx but that where clause looks suspect. On the surface it looks like it’s only seeing the last 10 seconds of information, then it looks like you sum that information?
I am using a simple folder sensor instead since I could never get a similar approach working.
sensor:
- platform: folder
folder: /mysql_data
I then mapped the influxdb data path as a volume named mysql_data in my HA docker config. This will of course only work if you are able to map the path to a volume, i.e. if influxDB is on the same machine as your HA instance.
See here: https://www.home-assistant.io/integrations/folder/
I’m running HA Core in Docker, so I can’t help with the mapping, but if you are running HassOS, it means that your influxDB folder is on the same system, so it seems doable. You just need to figure out where the influxdb data folder is, and how to map a volume.
Ok, so it might be difficult. If you can ssh out of the container to the host with a command line sensor, you might be able to do a simple du -s
to get the folder size, if you can find the folder.
This works from the SSH ad Web Terminal Addon with protection mode disabled:
docker exec addon_a0d7b954_influxdb du -s /data/influxdb/data/homeassistant
However according to Frenk there is no way yo access that from within home assistant. So dead end and the only option for Home assistant users is the unreliable and (and frankly incorrect) shard method. Which is also not an option if you disable the internal database - as recommended by InfluxDB themselves.
Only solution: If you want a reliable sensor choose another install method that allows access to docker container files.
Using the file sensor I should be able to get this into home assistant as a sensor. I’m going to increase the watch time to 3000 seconds, 10 was just to test. The only downside is that the web terminal no longer works with ingress. Guess I’ll have to use the core SSH addon for access.
The confusing thing is that redirecting the command output with > should overwrite the file but instead it is appending to the file.
docker exec addon_a0d7b954_influxdb du -s /data/influxdb/data/homeassistant > /config/file_sensors/ha_influx_db_size.txt
This:
while [ 1 = 1 ]; do docker exec addon_a0d7b954_influxdb du -s /data/influxdb/data/homeassistant > /config/file_sensors/ha_influx_db_size.txt sleep 10; done
Returns:
du: cannot access '10' : No such file or directory
EDIT: I see my missing &&.
Edit 2: So the configuration is changed to this on saving:
init_commands:
- >-
while [ 1 = 1 ]; do docker exec addon_a0d7b954_influxdb du -s
/data/influxdb/data/homeassistant >
/config/file_sensors/ha_influx_db_size.txt && sleep 300; done
And while it is overwriting this 352808 /data/influxdb/data/homeassistant to the file, I still get 502: Bad Gateway when attempting to open the web terminal. Seems an awful waste of this addon.
@tom_l don’t give up hope on that amazing plugin… there’s a simple solution to your issue. Just throw ampersand at the end which turns the Linux command into a “background” task. It should just look like the below just pay attention to that last ampersand.
init_commands:
- 'while [ 1 = 1 ]; do du -s /etc > /backup/test.txt && sleep 10; done &'