munin-monitoring / contrib

Contributed stuff for munin (plugins, tools, etc...)
http://munin-monitoring.org
1.05k stars 683 forks source link

docker_ error for memory #1447

Open msgrt opened 2 months ago

msgrt commented 2 months ago

docker_ plugin stops the execution in the memory section with the following error:

multigraph docker_memory
Traceback (most recent call last):
  File "/etc/munin/plugins/docker_multi", line 579, in <module>
    main()
  File "/etc/munin/plugins/docker_multi", line 572, in main
    globals()[s](client, mode)
  File "/etc/munin/plugins/docker_multi", line 519, in memory
    print_containers_memory(client)
  File "/etc/munin/plugins/docker_multi", line 317, in print_containers_memory
    memory_usage = stats['memory_stats']['usage']
                   ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'usage'

Raspberry OS/Debian Bookworm Docker CE 27.1.2 Python 3.11.2

Any ideas how to get this to work?

kenyon commented 2 months ago

I'd guess that the Docker API doesn't provide the usage key anymore. You could debug this by printing the value of stats inside print_containers_memory.

kenyon commented 2 months ago

Although, I see in the API docs that there should be a usage key, so 🤷 https://docs.docker.com/engine/api/v1.46/#tag/Container/operation/ContainerStats

kenyon commented 2 months ago

You can see what the Docker API is providing like this:

curl --unix-socket /var/run/docker.sock http://localhost/v1.46/containers/<container ID>/stats | jq --color-output .
msgrt commented 2 months ago

Thank you very much @kenyon . Unfortunately no usage values here. I have tested with all the containers I have running. The last 4 values given in the example in the documentation (max_usage, usage, failcnt, limit) are missing for me.

  "memory_stats": {
    "stats": {
      "active_anon": 0,
      "active_file": 0,
      "anon": 0,
      "anon_thp": 0,
      "file": 0,
      "file_dirty": 0,
      "file_mapped": 0,
      "file_writeback": 0,
      "inactive_anon": 0,
      "inactive_file": 0,
      "kernel_stack": 0,
      "pgactivate": 0,
      "pgdeactivate": 0,
      "pgfault": 0,
      "pglazyfree": 0,
      "pglazyfreed": 0,
      "pgmajfault": 0,
      "pgrefill": 0,
      "pgscan": 0,
      "pgsteal": 0,
      "shmem": 0,
      "slab": 0,
      "slab_reclaimable": 0,
      "slab_unreclaimable": 0,
      "sock": 0,
      "thp_collapse_alloc": 0,
      "thp_fault_alloc": 0,
      "unevictable": 0,
      "workingset_activate": 0,
      "workingset_nodereclaim": 0,
      "workingset_refault": 0
    }
  },