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

docker info:

- check status output "(healthy)"
- speedup output of containers
parent 825d05ac
No related branches found
No related tags found
1 merge request!308docker info:
...@@ -19,13 +19,14 @@ ...@@ -19,13 +19,14 @@
# 2024-01-29 v1.4 <axel.hahn@unibe.ch> add --target option # 2024-01-29 v1.4 <axel.hahn@unibe.ch> add --target option
# 2024-02-13 v1.5 <axel.hahn@unibe.ch> update docker ps --format # 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-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
# ====================================================================== # ======================================================================
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "$( dirname "$0" )/inc_pluginfunctions" || exit 1 . "$( dirname "$0" )/inc_pluginfunctions" || exit 1
. "$( dirname "$0" )/inc_dockerfunctions.sh" || exit 1 . "$( dirname "$0" )/inc_dockerfunctions.sh" || exit 1
self_APPVERSION=1.6 self_APPVERSION=1.7
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
...@@ -66,8 +67,8 @@ OPTIONS: ...@@ -66,8 +67,8 @@ OPTIONS:
multiple users run a rootless docker daemon. multiple users run a rootless docker daemon.
Flags: Flags:
-c, --containers Flag: Show containers (slow) -c, --containers Flag: Show containers
-e, --errors Flag: Show containers on error only (slow) -e, --errors Flag: Show containers on error only
EXAMPLES: EXAMPLES:
$_self $_self
...@@ -75,7 +76,7 @@ EXAMPLES: ...@@ -75,7 +76,7 @@ EXAMPLES:
$_self -c $_self -c
Show Status of all containers and a list of container names with its Show Status of all containers and a list of container names with its
status. Warning: this feature uses docker ps --all and can be slow. status.
$_self -e $_self -e
Show Status of all containers. If not all containers are running you Show Status of all containers. If not all containers are running you
...@@ -178,20 +179,23 @@ echo "$out" ...@@ -178,20 +179,23 @@ echo "$out"
if [ $bOptContainers -eq 1 ] && [ "$iCTotal" -gt "0" ]; then if [ $bOptContainers -eq 1 ] && [ "$iCTotal" -gt "0" ]; then
echo echo
echo "Containers:" echo "Containers:"
# containers=$( sudo -n --preserve-env docker ps --all --format "{{ json . }}" --all 2>/dev/null ) # 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 --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 )
echo "$containers" | while read -r line; do echo "$containers" | while read -r line; do
sName=$( _getString "$line" ".Names" ) contStatus="OK"
sState=$( _getString "$line" ".State" ) if grep -q "(" <<< "$line"; then
sStatus=$( _getString "$line" ".Status" ) if grep -Fv "(healthy)" <<< "$line" | grep -q "("; then
sIco= contStatus="??"
# Icinga ui does not show these characters # commented because within a while loop I am in a subshell
# sIco="🔶" # ph.setStatus critical
# grep "exited" <<< "${sState}" >/dev/null && sIco="❌" fi
# grep "running" <<< "${sState}" >/dev/null && sIco="✅" else
if ! grep -q "| running |" <<< "$line"; then
printf " %-14s %-40s %-20s\n" "$sIco $sState" "$sName" "$sStatus" contStatus="??"
fi
fi
echo "$contStatus $line"
done done
echo echo
......
...@@ -37,7 +37,7 @@ If DOCKER_HOST is not set then the docker socket is detected from a running dock ...@@ -37,7 +37,7 @@ If DOCKER_HOST is not set then the docker socket is detected from a running dock
______________________________________________________________________ ______________________________________________________________________
CHECK_DOCKER_INFO CHECK_DOCKER_INFO
v1.6 v1.7
(c) Institute for Medical Education - University of Bern (c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3 Licence: GNU GPL 3
...@@ -73,8 +73,8 @@ OPTIONS: ...@@ -73,8 +73,8 @@ OPTIONS:
multiple users run a rootless docker daemon. multiple users run a rootless docker daemon.
Flags: Flags:
-c, --containers Flag: Show containers (slow) -c, --containers Flag: Show containers
-e, --errors Flag: Show containers on error only (slow) -e, --errors Flag: Show containers on error only
EXAMPLES: EXAMPLES:
check_docker_info check_docker_info
...@@ -82,7 +82,7 @@ EXAMPLES: ...@@ -82,7 +82,7 @@ EXAMPLES:
check_docker_info -c check_docker_info -c
Show Status of all containers and a list of container names with its Show Status of all containers and a list of container names with its
status. Warning: this feature uses docker ps --all and can be slow. status.
check_docker_info -e check_docker_info -e
Show Status of all containers. If not all containers are running you Show Status of all containers. If not all containers are running you
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment