diff --git a/check_dockercontainer_top b/check_dockercontainer_top index 4dac969ddfdaaea805b56c6d50c10ba6304024c8..7d8179e8d2a668885f1336f4e200284e42a51580 100755 --- a/check_dockercontainer_top +++ b/check_dockercontainer_top @@ -13,13 +13,14 @@ # https://docs.docker.com/engine/reference/commandline/docker/ # ---------------------------------------------------------------------- # 2024-01-26 v1.0 <axel.hahn@unibe.ch> init +# 2024-01-29 v1.1 <axel.hahn@unibe.ch> fix help; # ====================================================================== . $(dirname $0)/inc_pluginfunctions . $(dirname $0)/inc_dockerfunctions.sh -self_APPVERSION=1.0 +self_APPVERSION=1.1 # ---------------------------------------------------------------------- # FUNCTIONS @@ -48,8 +49,12 @@ USAGE: $_self [OPTIONS] OPTIONS: + + General: -h, --help this help - -d, --debug Debug; Flag: show all docker system infos + -d, --debug Debug; Flag: show docker env values. + + 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 @@ -91,7 +96,7 @@ while [[ "$#" -gt 0 ]]; do case $1 in fi shift; shift;; -t|--target) export DOCKER_HOST="$2"; shift; shift;; - *) echo "ERROR: Unknown parameter: $1"; showHelp; exit 1; + *) echo "ERROR: Unknown parameter: $1"; _showHelp; exit 1; esac; done ph.require "docker" @@ -108,7 +113,7 @@ _detectDockererror "$data" out=$( echo "$data" | while read -r line; do - id=$( echo "$line" | jq -r ".ID") + id=$( echo "$line" | jq -r ".ID") name=$( echo "$line" | jq -r ".Names") pslist=$( sudo -n --preserve-env docker top "$id" "-o user,pid,pcpu,pmem,command" 2>/dev/null ) @@ -121,7 +126,7 @@ done typeset -i iContainers; iContainers=$( echo "$data" | wc -l ) typeset -i iLines; iLines=$( echo "$out" | wc -l ) -typeset -i iProcesses; iProcesses=iLines-iContainers*2 +typeset -i iProcesses; iProcesses=$(( iLines-iContainers*2 )) # --- output diff --git a/inc_dockerfunctions.sh b/inc_dockerfunctions.sh index 3b94193e059c199ea158624d20abaa3aad22362c..761ab31e3dba73d42d0f192ed39fc61a53937b92 100644 --- a/inc_dockerfunctions.sh +++ b/inc_dockerfunctions.sh @@ -43,9 +43,11 @@ function _getString(){ function _detectDockerenv(){ local dockeruid= if [ -z "$DOCKER_HOST" ]; then - _is_docker_detected=1 dockeruid=$( ps -ef | grep containerd | grep -Eo "/run/user/([0-9]*)/" | head -1 | cut -f 4 -d '/' ) - test -n "$dockeruid" && export DOCKER_HOST="unix:///run/user/$dockeruid/docker.sock" + if [ -n "$dockeruid" ]; then + _is_docker_detected=1 + export DOCKER_HOST="unix:///run/user/$dockeruid/docker.sock" + fi # Don't abort - it is allowed that the variable DOCKER_HOST is missing fi if grep "/run/user/[0-9]*" <<< "$DOCKER_HOST" >/dev/null; then