ualex73 / monitor_docker

Monitor Docker containers from Home Assistant
Apache License 2.0
289 stars 35 forks source link

Trying to get the containers_memory_percent to come through, and it's only giving me the total memory MB totals. #18

Closed sstratoti closed 4 years ago

sstratoti commented 4 years ago

Great component!

I'm attempting to set up a pie chart in my system monitor page that'll show me which docker containers are using the most cpu and memory.

I'm trying to get the containers_memory_percent to come through, and it's only giving me the total memory MB totals.

Config is:

monitor_docker:
  - name: Docker
    rename:
      db: MySQL
      docker_owncloud_1: OwnCloud
      docker_room-assistant_1: Room-Assistant
      grafana: Grafana
      plex: "Plex"
      home-assistant: Home Assistant
      influxdb: InfluxDB
      mqtt: Mosquitto
      nodered: "Node-RED"
      portainer: Portainer
      letsencrypt: LetsEncrypt
      openvpn: OpenVPN
    monitored_conditions:
      - version
      - containers_running
      - containers_total
      - containers_stopped
      - containers_memory_percentage
      - containers_cpu_percentage
      - uptime
      - state
      - status
      - memory

I do see a sensor for: sensor.docker_memory_percent (overall docker system memory), but not for each of the individual containers. For each container I see sensors that resemble sensor.docker_db_memory with the MB total for the container.

I can see this data in the debug log. Not sure if I'm missing something in the config. Thanks!

Sample from debug log:

2020-07-08 12:48:47 DEBUG (Thread-3) [custom_components.monitor_docker.helpers] Version: 19.03.12, Containers: 12, Running: 12, CPU: None%, Memory: 1282.55MB, 8.06%
2020-07-08 12:48:49 DEBUG (Thread-3) [custom_components.monitor_docker.helpers] nodered: CPU Usage=7.09%. Memory Usage=132.35MB, 0.83%
2020-07-08 12:48:49 DEBUG (Thread-3) [custom_components.monitor_docker.helpers] nodered: Send notify (5) to container
2020-07-08 12:48:49 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] nodered: Received callback for: Up Time
2020-07-08 12:48:49 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] nodered: Received callback for: State
2020-07-08 12:48:49 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] nodered: Received callback for: Status
2020-07-08 12:48:49 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] nodered: Received callback for: Memory
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.helpers] home-assistant: CPU Usage=58.68%. Memory Usage=360.41MB, 2.27%
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.helpers] home-assistant: Send notify (5) to container
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] home-assistant: Received callback for: Up Time
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] home-assistant: Received callback for: State
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] home-assistant: Received callback for: Status
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] home-assistant: Received callback for: Memory
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.helpers] portainer: CPU Usage=0.04%. Memory Usage=9.47MB, 0.06%
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.helpers] portainer: Send notify (5) to container
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] portainer: Received callback for: Up Time
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] portainer: Received callback for: State
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] portainer: Received callback for: Status
2020-07-08 12:48:51 DEBUG (Thread-3) [custom_components.monitor_docker.sensor] portainer: Received callback for: Memory
ualex73 commented 4 years ago

Yes, the containers_memory is for all containers. To have it per container, add the following one: memory_percentage

sstratoti commented 4 years ago

Woohoo! Thank you!

Also, don't know if you saw this post:

https://www.reddit.com/r/homeassistant/comments/hmqmco/a_few_more_tweaks_needed_before_ive_completed_my/

But the user describes a step where you need to modify the docker.service file:

ExecStart=/usr/bin/dockerd` -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0

I didn't see that in your install instructions, so I thought I'd mention it. :) Thanks again!

ualex73 commented 4 years ago

@sstratoti thanks for the link and other information. Which Linux distribution are you using? I myself us Ubuntu 18.04 with Docker CE and it worked directly (no manual changes required). Also, is the monitor_docker connection to a remote Docker host or really locally?