Table of Contents
CHECK_DOCKER_SWARM_SERVICES
Script: check_docker_swarm_services
check_docker_swarm_services shows the service status of a docker swarm cluster. It checks the replicas for each service and warns you if less containers than required replicas atre running.
This check sends performance data.
Requirements
dockerDocker must be installedjqmust be installed - commandline JSON processor- 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_pluginfunctionsshared function for all IML checks written in bashinc_dockerfunctions.sh
Syntax
______________________________________________________________________
CHECK_DOCKER_SWARM_SERVICES
v0.1
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_docker_swarm_services.html
______________________________________________________________________
Show docker services
It returns
CRITICAL if a service has no running container
WARNING if a service runs with less than wanted replicas
OK if all services are up and running
UNKNOWM if
- docker or jq were not found
- docker data were not fetched
- docker cannot be connected
- This host is not a swarm manager
This check provides performance data.
USAGE:
check_docker_swarm_services [OPTIONS]
OPTIONS:
General:
-h, --help this help
-d, --debug Debug; Flag: add json of all docker services
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:
-s, --services Flag: Show services
-e, --errors Flag: Show containers on error only
EXAMPLES:
check_docker_swarm_services
Show a short status of all services
check_docker_swarm_services -e
Show short status with all services. Non OK services will be shown.
check_docker_swarm_services -s
Show long status with all services and its state.
check_docker_swarm_services -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_swarm_services -d
Add json with all docker service infos
Parameters
None.
Examples
Short status
Without given options it returns a short info.
$ ./check_docker_swarm_services
CRITICAL: Docker swarm services 13 ... OK: 12 warnings: 0 errors: 1
|services-ok=12;;;0;13 services-warning=0;;;0;13 services-critical=1;;;0;13
Short status - but show errors
You can enable to display services with problems using -eor --errors:
$ ./check_docker_swarm_services -e
CRITICAL: Docker swarm services 13 ... OK: 12 warnings: 0 errors: 1
[CRITICAL] d0cy4cqb9po1 portainer_monitoring_sc_prometheus replicated 0/1 prom/prometheus:v3.7.3
|services-ok=12;;;0;13 services-warning=0;;;0;13 services-critical=1;;;0;13
Long status
If your cluster has not too many services you maybe wantto enalbe all services using -sor --services
./check_docker_swarm_services -s
CRITICAL: Docker swarm services 13 ... OK: 12 warnings: 0 errors: 1
[OK] m9ccua40swj9 measured-analytics-stage_analytics-stage replicated 1/1 ghcr.io/***/measured-***:5.31.0
[OK] ycegn39he8c6 measured_opencpu_docker_stage_opencpu_stage replicated 1/1 git.example.com:4567/***/analytics-package:master
[OK] h23lwpliyix6 measured_static_measured-static replicated 2/2 git.example.com:4567/***/measured-static:master
[OK] anxf65r8ctop morpheus-stage_morpheus-stage replicated 1/1 ghcr.io/***/morpheus:1.3.0
[OK] g85brj2zwulk portainer_agent global 3/3 portainer/agent:2.39.3
[OK] m6ekpktqqe0d portainer_monitoring_sc_cadvisor global 3/3 gcr.io/cadvisor/cadvisor:v0.54.1
[OK] g74g8ezlvp1l portainer_monitoring_sc_dashboard replicated 1/1 mohsenasm/swarm-dashboard:latest
[OK] xhoib20ex2dx portainer_monitoring_sc_grafana replicated 1/1 grafana/grafana:12.3.0-ubuntu
[OK] jiknf3kycukg portainer_monitoring_sc_node-exporter global 3/3 prom/node-exporter:v1.10.2
[CRITICAL] d0cy4cqb9po1 portainer_monitoring_sc_prometheus replicated 0/1 prom/prometheus:v3.7.3
[OK] 0cwpg6s9uy84 swarm_memcached_sc_memcached replicated 1/1 memcached:1.6.39 *:11211->11211/tcp
[OK] qtkfu0uns9pa swarm_memcached_sc_memcachedadmin replicated 1/1 hatamiarash7/memcached-admin:latest
[OK] vdmiphrnq6bt swarm_proxy_reverse-proxy replicated 2/2 traefik:v3.7.1 *:80->80/tcp, *:443->443/tcp, *:8081->8081/tcp
|services-ok=12;;;0;13 services-warning=0;;;0;13 services-critical=1;;;0;13
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.