Skip to content
Snippets Groups Projects
Commit 45e7ae04 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '8066-docker-health' into 'master'

docker_server_info - better output of containers

See merge request !310
parents d4eb4d54 0798d865
No related branches found
No related tags found
1 merge request!310docker_server_info - better output of containers
......@@ -20,13 +20,14 @@
# 2024-02-13 v1.5 <axel.hahn@unibe.ch> update docker ps --format
# 2025-02-10 v1.6 <axel.hahn@unibe.ch> harden sourcing files
# 2025-06-23 v1.7 <axel.hahn@unibe.ch> check status output "(healthy)"; speedup output of containers
# 2025-06-23 v1.8 <axel.hahn@unibe.ch> better output of containers
# ======================================================================
# shellcheck source=/dev/null
. "$( dirname "$0" )/inc_pluginfunctions" || exit 1
. "$( dirname "$0" )/inc_dockerfunctions.sh" || exit 1
self_APPVERSION=1.7
self_APPVERSION=1.8
# ----------------------------------------------------------------------
# FUNCTIONS
......@@ -177,25 +178,25 @@ if [ $bOptContainers -eq 1 ] && [ "$iCTotal" -gt "0" ]; then
out+="$(
echo
echo "Containers:"
printf "%-4s %-8s %-25s %s\n" "" "STATE" "STATUS" "NAME"
# containers=$( sudo -n --preserve-env docker ps --all --format '{"Names": "{{.Names}}", "State": "{{.State}}", "Status": "{{.Status}}" }' 2>/dev/null )
containers=$( sudo -n --preserve-env docker ps --format "table {{.Names}} | {{.State}} | {{.Status}}" --all 2>/dev/null | sed -n 2,\$p )
containers=$( sudo -n --preserve-env docker ps --format "table {{.State}}|{{.Status}}|{{.Names}}" --all 2>/dev/null | sed -n 2,\$p )
echo "$containers" | while read -r line; do
echo "$containers" | while IFS=\| read -r state status name ; do
contStatus="OK"
if grep -q "(" <<< "$line"; then
if grep -Fv "(healthy)" <<< "$line" | grep -q "("; then
if grep -q "(" <<< "$status"; then
if grep -Fv "(healthy)" <<< "$status" | grep -q "("; then
contStatus="??"
# commented because within a while loop I am in a subshell
# ph.setStatus critical
fi
else
if ! grep -q "| running |" <<< "$line"; then
if ! grep -q "running" <<< "$state"; then
contStatus="??"
fi
fi
echo "$contStatus $line"
# echo "$contStatus $state $status $name"
printf "%-4s %-8s %-25s %s\n" "$contStatus" "$state" "$status" "$name"
done
done | sort -h
echo
)"
fi
......
......@@ -37,7 +37,7 @@ If DOCKER_HOST is not set then the docker socket is detected from a running dock
______________________________________________________________________
CHECK_DOCKER_INFO
v1.7
v1.8
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
......@@ -103,12 +103,36 @@ None.
## Examples
### Simple call
`$ ./check_docker_info` returns
```txt
OK: Docker 20.10.14 (Community Engine, rootless) .. containers: 2 running: 2 paused: 0 stopped: 0 .. images: 5
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
```txt
K: Docker 28.2.2 (as root) .. containers: 10 running: 10 paused: 0 stopped: 0 .. images: 9
All containers are running
|containers-running=2;;;0;2 containers-paused=0;;;0;2 containers-stopped=0;;;0;2 images=33;;
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment