Python script to check various aspects of Docker and Docker Swarm. It can verify that the daemon is up, is a part of a Swarm, and if Swarm services are healthy.
The check-docker.py
script is a re-implentation of check_docker using the native Docker Python SDK and combines it into a single command.
To use as an asset, clone this repository and create a tarball using make
.
git clone https://github.com/KSU-Linux/check-docker.git
cd check-docker
make all
This will generate the files check-docker.tar.gz
and sha512sum.txt
. You will need to upload check-docker.tar.gz
to a downloadable URL which you can then reference in a Sensu Go asset definition.
---
type: Asset
api_version: core/v2
metadata:
name: check-docker
spec:
builds:
- url: https://example.com/check-docker.tar.gz
sha512: ${SHA512SUM}
filters:
- entity.system.os == 'linux'
- entity.system.arch == 'amd64'
- url: https://example.com/check-docker.tar.gz
sha512: ${SHA512SUM}
filters:
- entity.system.os == 'linux'
- entity.system.arch == '386'
In order for Sensu Go to run docker
commands, add the user to the docker
group on systems that will use the check.
gpasswd -a sensu docker
This check will verify that the Docker daemon is up and repsonsive.
./check-docker.py --ping
OK: docker is up
This check will confirm that there is at least 1 container up and running.
./check-docker.py --containers
OK: 4 running containers
You can modify the minimum and maximum running containers for the --containers
check using --min
and --max
respectively.
./check-docker.py --containers --min 1 --max 4
OK: 4 running containers
This check will check the node is part of a Swarm.
./check-docker.py --swarm
OK: Docker Swarm enabled
This check confirms that the node is a Swarm manager.
./check-docker.py --swarm-manager
OK: Node is a manager
This check can be used to verify that one or more Swarm services are healthy.
./check-docker.py --swarm-service jirafeau_app traefik_proxy
OK: Docker Swarm service 'jirafeau_app' replicas 2/2; OK: Docker Swarm service 'traefik_proxy' replicas 2/2
This check verifies all services in the Swarm.
./check-docker.py --swarm-services
OK: Docker Swarm service 'jirafeau_app' replicas 2/2; OK: Docker Swarm service 'traefik_proxy' replicas 2/2