Trying to use command_line extension

Hi there,

I put in my configuration.yaml the following code in order to configure mem usage of home-assistant core installed in a qnap docker container:

command_line:
  - sensor:
      name: prova
      command: "docker stats --no-stream --format '{{.MemUsage}}' home-assistant"

I get the sensor called “prova”, but its value is always unknown.
I tried to run the command from qnap SSH terminal and it works.

The command runs within the docker container. You can either try to ssh to qnap but you could also (for this purpose), use something like this

ualex73/monitor_docker: Monitor Docker containers from Home Assistant

If you only need to monitor HA usage, then I suggest you try the System Monitor integration first.

It’ll create a bunch of sensors for you out of the box, though some (like CPU Temperature) might be stuck on unknown/unavailable. Memory should work out of the box though.

1 Like

Thx, did not even know this existed :slight_smile:

I used it both.
System Monitor doesn’t capture the real statistics, I compared values and are completely different.
About Monitor Docker I added in configuration.yaml the following (the name of the docker is home-assistant):

monitor_docker:
  - name: Docker
    containers:
      - home-assistant
    rename:
      home-assistant: home-assistant
    monitored_conditions:
      - version
      - containers_running
      - containers_total
      - state
      - status
      - memory

Rebooted fast of home assistant doesn’t create any sensors.

Ah…yes…the qnap element, let me check here.

I tried also to put the code into sensors.yaml like this:

- platform: monitor_docker
   name: Docker
   containers:
     - home-assistant
   rename:
     home-assistant: home-assistant
   monitored_conditions:
    - version
    - containers_running
    - containers_total
    - state
    - status
    - memory

But neither this works.

PS: yes, I have the docker with homeassistant core hosted on my Qnap NAS.

NAS’s have their particularities, I have both a Syno and a Qnap and both come with ‘fun’
Tbh, I never installed HA on Qnap but supposedly, if you run it on host, it should have connected imo.
From my current HA, on a nuc (yet another system …yes) I run this:

  - name: DockerQNAP
    url: tcp://IP-OF-QNAP:2375
    scan_interval: 240
    containers:
      - music_assistant_test
      - music_assistant
      - spotweb2
    monitored_conditions:
      - version
      - containers_running
      - containers_total
      - containers_1cpu_percentage
      - containers_cpu_percentage
      - containers_memory
      - containers_memory_percentage
      - state
      - status
      - cpu_percentage
      - memory
      - memory_percentage

But… as with Syno, I first needed to make the socket available via socat. And this does exist on Syno, not on Qnap.
In my notes to install on Qnap I have this:

make containers available for monito_docker via socat
1. Install socat on Qnap: curl -L -o /share/CACHEDEV1_DATA/socat "https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat"
2. Test if it works: /share/CACHEDEV1_DATA/socat -V
3. start it : /share/CACHEDEV1_DATA/socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
4. verify version locally: curl http://127.0.0.1:2375/version
5. verify from remote machine: curl http://IP-OF-QNAP:2375/version
6. if fine: make it stable'on Qnap: 
echo '/share/CACHEDEV1_DATA/socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &' \
  >> /etc/config/autorun.sh
chmod +x /etc/config/autorun.sh
cat /etc/config/autorun.sh
7. use tcp://IP-OF-QNAP:2375 in monitor_docker