From fbc03dc1c2926134b28b2a233904056e514e7fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o?= <theo@le-filament.com> Date: Wed, 11 May 2022 17:10:17 +0200 Subject: [PATCH] fix retrieval of not running conatiners --- check_docker.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/check_docker.sh b/check_docker.sh index 83e0a8d..7e05f50 100755 --- a/check_docker.sh +++ b/check_docker.sh @@ -48,11 +48,11 @@ while [[ $# -gt 0 ]]; do done # Gathering facts. -all_containers=`sudo docker ps --format '{{.Names}}' --filter "name=${filter}" --no-trunc --quiet --all` -running_containers=`sudo docker ps --format '{{.Names}}' --filter "name=${filter}" --no-trunc --quiet` -running_containers_stats=`sudo docker stats --format '{{.Name}}:{{.CPUPerc}}:{{.MemPerc}}' --no-stream` +all_containers=`sudo /usr/bin/docker ps --format '{{.Names}}' --filter "name=${filter}" --no-trunc --quiet --all` +running_containers=`sudo /usr/bin/docker ps --format '{{.Names}}' --filter "name=${filter}" --no-trunc --quiet` +running_containers_stats=`sudo /usr/bin/docker stats --format '{{.Name}}:{{.CPUPerc}}:{{.MemPerc}}' --no-stream` -not_running_containers=`comm -23 <(echo $all_containers) <(echo $running_containers)` +not_running_containers=`comm -23 <(echo $all_containers | /usr/bin/tr ' ' '\n') <(echo $running_containers | /usr/bin/tr ' ' '\n')` # Format data. output='' @@ -72,10 +72,10 @@ done # CPU and memory statistics for running containers. for container_stats in ${running_containers_stats}; do - name=`awk -F ':' '{print $1}' <(echo $container_stats)` + name=`/usr/bin/awk -F ':' '{print $1}' <(echo $container_stats)` [[ ! $name =~ ${filter} ]] && continue - cpu=`awk -F ':' '{print +$2}' <(echo $container_stats)` - mem=`awk -F ':' '{print +$3}' <(echo $container_stats)` + cpu=`/usr/bin/awk -F ':' '{print +$2}' <(echo $container_stats)` + mem=`/usr/bin/awk -F ':' '{print +$3}' <(echo $container_stats)` status='OK' [[ ${cpu%.*} -ge $cpu_threshold_warning ]] && status='WARNING' -- GitLab