Table of Contents
CHECK_DOCKER_INFO
Script: check_docker_info
check_docker_info_ shows the docker version and count of containers. You get the count of containers by state running, paused or stopped. This check sends performance data.
Requirements
-
docker
Docker must be installed -
jq
Docker must be installed - sudo permissions on docker command
icingaclient ALL=(ALL) NOPASSWD:SETENV: /usr/bin/docker
Standalone installation
From this repository you need next to this script:
-
inc_pluginfunctions
shared function for all IML checks written in bash -
inc_dockerfunctions.sh
Rootless docker
It works with docker setups as root and can handle rootless docker instances.
To bring it up and running with an unpriviledged icinga user it must be able to access docker. Copy the docker binary eg. from /home/dockeruser/bin/docker to /usr/bin/. Then use the parameter -p /usr/bin
.
If DOCKER_HOST is not set then the docker socket is detected from a running docker instance and will be fetched from the process list.
Syntax
______________________________________________________________________
CHECK_DOCKER_INFO
v1.8
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_docker_info.html
______________________________________________________________________
Show docker version and count of containers total and by its status.
It returns
CRITICAL if a created container is not running.
OK if no container was created yet or all conmtainers are running.
UNKNOWM if
- docker or jq were not found
- docker data were not fetched
- docker cannot be connected
This check provides performance data.
USAGE:
check_docker_info [OPTIONS]
OPTIONS:
General:
-h, --help this help
-d, --debug Debug; Flag: show all docker system infos
Connect to docker:
-p, --path Custom directory for docker binary
-t, --target Custom docker target; value for DOCKER_HOST
Needed only if Docker does not run on a unix socket or
multiple users run a rootless docker daemon.
Flags:
-c, --containers Flag: Show containers
-e, --errors Flag: Show containers on error only
EXAMPLES:
check_docker_info
Show Status of all containers
check_docker_info -c
Show Status of all containers and a list of container names with its
status.
check_docker_info -e
Show Status of all containers. If not all containers are running you
get a list of container names with its status.
check_docker_info -p /usr/bin
Show Status of all containers. The docker binary will be searched in
given path first - then in all other dirs of $PATH
check_docker_info -d
Show Status of all containers and json with all docker system infos.
Parameters
None.
Examples
Simple call
$ ./check_docker_info
returns
OK: Docker 28.2.2 (as root) .. containers: 10 running: 10 paused: 0 stopped: 0 .. images: 9
All containers are running
|containers-running=10;;;0;10 containers-paused=0;;;0;10 containers-stopped=0;;;0;10 images=9;;
Show containers
$ ./check_docker_info -c
returns
K: Docker 28.2.2 (as root) .. containers: 10 running: 10 paused: 0 stopped: 0 .. images: 9
All containers are running
Containers:
STATE STATUS NAME
OK running Up 10 days (healthy) portainer_monitoring_se_cadvisor.3pir5zn6akrpplsw8qyn4oln0.ktk7q9aducr73tsg0te7i4sog
OK running Up 10 days (healthy) portainer_monitoring_se_dashboard.1.7lpcny6uyrgnig1n2zefixjkl
OK running Up 10 days (healthy) portainer_monitoring_se_grafana.1.292vzy9n4s00bm7iz9bzto5a9
OK running Up 10 days (healthy) portainer_monitoring_se_node-exporter.3pir5zn6akrpplsw8qyn4oln0.50vs3fy3a479ndh8tjlp8bqlj
OK running Up 10 days (healthy) portainer_monitoring_se_prometheus.1.bjy5tad8otl2qunpn3p65k3cd
OK running Up 13 days xyz-demo.1.6n15jjras1k6vvs64zhcakgvl
OK running Up 13 days xyz-live.2.piuh38de5c4a89yw3fftmzjb0
OK running Up 13 hours swarm_proxy_reverse-proxy.1.qrqwup8xlyoek9oysx0lg42bt
OK running Up 6 days whoami_whoami.1.6jrqbtv85ag0y7f1mc0falzd1
OK running Up 7 days portainer_agent.3pir5zn6akrpplsw8qyn4oln0.dl3hsnmnjgcanqfquu9q772s2
|containers-running=10;;;0;10 containers-paused=0;;;0;10 containers-stopped=0;;;0;10 images=9;;
Troubleshooting
Missing environment
sudo: sorry, you are not allowed to preserve the environment
UNKNOWN: No data. Unable to fetch Docker information.
Solution: you did not set SETENV in the sudoers config file
icingaclient ALL=(ALL) NOPASSWD:SETENV: /usr/bin/docker
Docker not found
If you get an error message that docker was not found then it is not reachable in ofe of the directories of $PATH. This can happen especialy in rootless docker instances.
Solution: Use the parameter -p /usr/bin
to define a target. Copy the docker binary there.