This a tiny tool to monitor the status of a docker swarm stack. It will output the status as prometheus metrics into an output file. This file can be served by a webserver and scraped by prometheus. Here is an example how the metrics can be displayed in Grafana:
Build the Docker image:
docker build -t stack-monitor .
Run the example stack:
docker stack deploy -c stack.yaml stack
Now you can visit the Grafana dashboard at http://localhost:3000. The default username and password is admin
and secret
. Or, you can visit the prometheus metrics endpoint directly:
curl http://localhost/metrics.txt
This will output something like this:
node_running_containers{node="docker-desktop"} 3
node_shutdown_containers{node="docker-desktop"} 21
node_ready{node="docker-desktop"} 1
node_active{node="docker-desktop"} 1
node_leader{node="docker-desktop"} 1
service_replicas{service="stack_dummy"} 1
service_desired_replicas{service="stack_dummy"} 4
service_is_partially_running{service="stack_dummy"} 1
service_is_down{service="stack_dummy"} 0
service_is_up{service="stack_dummy"} 0
service_replicas{service="stack_stack-monitor"} 1
service_desired_replicas{service="stack_stack-monitor"} 1
service_is_partially_running{service="stack_stack-monitor"} 0
service_is_down{service="stack_stack-monitor"} 0
service_is_up{service="stack_stack-monitor"} 1
service_replicas{service="stack_stack-monitor-nginx"} 1
service_desired_replicas{service="stack_stack-monitor-nginx"} 1
service_is_partially_running{service="stack_stack-monitor-nginx"} 0
service_is_down{service="stack_stack-monitor-nginx"} 0
service_is_up{service="stack_stack-monitor-nginx"} 1
To integrate this tool with your stack, please check the stack.yaml
file.
Apache License 2.0