added memory info

restyled bars
changed logics in generate docker info
added sorting to services
changed temp scanner (maybe would be optimized)
This commit is contained in:
2024-11-16 00:50:50 +03:00
parent 07fbc5711c
commit e244affe6e
7 changed files with 141 additions and 112 deletions

View File

@@ -10,73 +10,55 @@ yellow="\e[1;33m"
undim="\e[0m"
docker_format='docker ps --format "{{.Names}} {{.Status}}" -a'
game_label='eval "$docker_format" --filter "label=game_server" -a | sort'
game_label='eval "$docker_format" --filter "label=game_server"'
traker='eval "$docker_format" --filter "label=traker"'
combined='(eval "$docker_format" --filter "label=traker" && eval "$docker_format" --filter "label=game_server") | sort'
mapfile -t containers < <( comm -2 -3 <( eval "$docker_format" | sort) <( eval "$combined") | sed '/^\s*$/d' | tail -n +1)
mapfile -t game_servers < <( eval "$game_label" | sort | sed '/^\s*$/d'| tail -n +1)
mapfile -t trakers < <( eval "$traker" | sort | sed '/^\s*$/d'| tail -n +1)
mapfile -t containers < <( comm -2 -3 <( eval "$docker_format" | sort) <(eval "$game_label") | sed '/^\s*$/d' | tail -n +1)
mapfile -t game_servers < <( eval "$game_label" | sed '/^\s*$/d'| tail -n +1)
check_status() {
IFS=" " read name status <<< $1
replica=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\2/')
name=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\1/')
if [[ "${status}" == *"healthy"* ]]; then
_status="${green}healthy${undim}"
elif [[ "${status}" == *"Restarting"* ]]; then
_status="${yellow}restarting${undim}"
elif [[ "${status}" == *"Paused"* ]]; then
_status="${yellow}paused${undim}"
elif [[ "${status}" == *"Up"* ]]; then
_status="${green}up${undim}"
elif [[ "${status}" == *"Created"* ]]; then
_status="${yellow}created${undim}"
elif [[ "${status}" == *"Exited"* ]]; then
_status="${red}exited${undim}"
fi
_line=${name},${_status}
echo -e "${name} ${_status}" | awk '{printf(" %-20s %+20s\n", $1, $2); }'
}
printf "\nDocker status:\n Game Servers:\n"
for i in "${!game_servers[@]}"; do
IFS2=" " read name status <<< ${game_servers[i]}
replica=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\2/')
name=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\1/')
check_status "${game_servers[$i]}"
done
if [[ "${status}" == *"healthy"* ]]; then
_status="${green}healthy${undim}"
elif [[ "${status}" == *"Restarting"* ]]; then
_status="${yellow}restarting${undim}"
elif [[ "${status}" == *"Paused"* ]]; then
_status="${yellow}paused${undim}"
elif [[ "${status}" == *"Up"* ]]; then
_status="${green}up${undim}"
elif [[ "${status}" == *"Created"* ]]; then
_status="${yellow}created${undim}"
elif [[ "${status}" == *"Exited"* ]]; then
_status="${red}exited${undim}"
fi
line=${name},${_status}
echo -e "${name} ${_status}" | awk '{printf(" %-20s %+25s\n", $1, $2); }'
printf "\n Tracker:\n"
for i in "${!trakers[@]}"; do
check_status "${trakers[$i]}"
done
printf "\n Other:\n"
for i in "${!containers[@]}"; do
IFS=" " read name status <<< ${containers[i]}
replica=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\2/')
name=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\1/')
if [[ "${status}" == *"healthy"* ]]; then
_status="${green}healthy${undim}"
elif [[ "${status}" == *"Restarting"* ]]; then
_status="${yellow}restarting${undim}"
elif [[ "${status}" == *"Paused"* ]]; then
_status="${yellow}paused${undim}"
elif [[ "${status}" == *"Up"* ]]; then
_status="${green}up${undim}"
elif [[ "${status}" == *"Created"* ]]; then
_status="${yellow}created${undim}"
elif [[ "${status}" == *"Exited"* ]]; then
_status="${red}exited${undim}"
fi
line=${name},${_status}
echo -e "${name} ${_status}" | awk '{printf(" %-20s %+25s\n", $1, $2); }'
check_status "${containers[$i]}"
done
printf ""