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

28
19-sysinfo Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# get processor name
cpu_info=$(cat /proc/cpuinfo)
cpu_model="$(echo "$cpu_info" | grep "model name" | sort -u | cut -d ':' -f 2)"
cpu_model=$(echo "$cpu_model" | sed -e "s/(R)//g" -e "s/(TM)//g" -e "s/ CPU//" -e "s/ Processor//" -e "s/ / /" -e "s/^ //g")
cpu_model=$(echo "$cpu_model" | sed "s/ with Radeon Graphics//")
cpu_model=$(echo "$cpu_model" | cut -d '@' -f 1)
distro=$(cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g')
_uptime=$(uptime -p | awk '{printf("%s %s %s %s\n", $2, $3, $4, $5); }' | sed 's/,//g')
# get processes
PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'`
PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}`
PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
W="\e[0;39m"
G="\e[1;33m"
printf "\n${W}System info:\n"
printf "$W Uptime.: $_uptime\n"
printf "$W Distro.: $distro\n"
printf "$W Kernel.: `uname -sr`\n"
printf "$W Proc...: $G$PROCESS_ROOT$W (r), $G$PROCESS_USER$W (u) | $G$PROCESS_ALL$W (t)\n"
printf "$W CPU....: %s\n" "$cpu_model"

38
20-memory Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
mapfile -t mem < <( free --mega)
IFS=$'\n' mem=($(sort <<<"${mem[*]}" | tail -n +2))
unset IFS
barWidth=38
clear="\e[39m\e[0m"
usageColor="\e[33m"
buffColor="\e[36m"
printf '\nMemory:\n'
for point in "${mem[@]}"; do
# printf "$point"
IFS=" " read TYPE USED TOTAL CACHE <<<$(echo "${point}" | awk {'print $1,$3,$2,$6'} | sed 's/://')
CACHE=$((CACHE+0))
usedBarWidth=$((barWidth*USED/TOTAL))
cachedBarWidth=$((barWidth*CACHE/TOTAL))
barContent="${usageColor}"
for sep in $(seq 1 $usedBarWidth); do
barContent="${barContent}―"
done
barContent="${barContent}${buffColor}"
for sep in $(seq 1 $cachedBarWidth); do
barContent="${barContent}―"
done
barContent="${barContent}${clear}"
for sep in $(seq 1 $(($barWidth-$usedBarWidth-$cachedBarWidth))); do
barContent="${barContent}―"
done
bar="${barContent}${clear}"
printf " %-4s used ${usageColor}%2s${clear} Gi cache ${buffColor}%3s${clear} Gi of %3s Gi\n" "$TYPE" "$(($USED/1024))" "$(($CACHE/1024))" "$(($TOTAL/1024))"
echo -e " ${bar}"
done

View File

@@ -1,23 +0,0 @@
#!/bin/bash
# get free memory
IFS=" " read USED FREE TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$4,$2'})
ISF2=" " read USEDSW FREESW TOTALSW <<<$(free -htm | grep "Swap" | awk {'print $3,$4,$2'})
# get processes
PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'`
PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}`
PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
W="\e[0;39m"
G="\e[1;33m"
echo -e "
${W}system info:
$W Uptime.: $W`uptime -p | awk '{if ($1 != "test") printf("%s %s %s %s\n", $2, $3, $4, $5); }' | sed 's/,//g'`
$W Distro.: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'`
$W Kernel.: $W`uname -sr`
$W Proc...: $W$G$PROCESS_ROOT$W (r), $G$PROCESS_USER$W (u) | $G$PROCESS_ALL$W (t)
$W CPU....:$W`cat /proc/cpuinfo | grep "name" | cut -d : -f2 | uniq | cut -f1 -d"@" | sed 's/(TM)//;s/(R)//;s/CPU//'`
$W Memory.: $G$USED$W used | $G$TOTAL$W in total$W
$W Swap...: $G$USEDSW$W used | $G$TOTALSW$W in total$W"

View File

@@ -1,12 +1,10 @@
#!/bin/bash
# mountpoints=$(echo df -h | grep ^/dev/ | grep -v efi | awk '{print $1;}')
mapfile -t mountpoints < <( df -h | grep ^/dev/ | grep -v efi | awk '{print $6;}' )
IFS=$'\n' mountpoints=($(sort <<<"${mountpoints[*]}"))
unset IFS
barWidth=40
barWidth=38
maxDiscUsage=85
midDiscUsage=45
clear="\e[39m\e[0m"
@@ -30,14 +28,14 @@ for point in "${mountpoints[@]}"; do
fi
barContent="${color}"
for sep in $(seq 1 $usedBarWidth); do
barContent="${barContent}"
barContent="${barContent}"
done
barContent="${barContent}${clear}${dim}"
barContent="${barContent}${clear}"
for sep in $(seq 1 $(($barWidth-$usedBarWidth))); do
barContent="${barContent}"
barContent="${barContent}"
done
bar=" ${barContent}${clear}"
echo "${point}" | awk '{printf(" %-14s", $1); }'
echo "${point}" | awk '{printf(" %-12s", $1); }'
echo "${line}" | awk '{if ($1 != "Filesystem") printf("%+8s used out of %+5s\n", $3, $2); }'
echo -e "${bar}"

View File

@@ -1,16 +1,16 @@
#!/bin/bash
disks=${disks:-()}
mapfile -t disks < <( ls /dev/sd[a-z] )
out=""
dim="\e[43m"
white="\e[31m"
label="\e[1;30m"
COLUMNS=3
clear="\e[0m\e[39m"
my_target_temp=45
k=0
for i in {a..z}; do
temp=$(smartctl -a /dev/sd${i} | grep Temperature_Celsius | grep 194 | awk '{print $10}' 2> /dev/null)
k=0
for i in ${disks[@]}; do
temp=$(smartctl -a ${i} | grep Temperature_Celsius | grep 194 | awk '{print $10}' 2> /dev/null)
color="\e[42m"
((k++))
if [ -z "$temp" ]; then
@@ -19,13 +19,13 @@ for i in {a..z}; do
if [ "$temp" -ge "${my_target_temp}" ]; then
color="\e[41m"
fi
out+="${dim}${white}${label} sd${i} \e[30m$color $temp $clear,"
out+="$(printf "${dim}${label} %s \e[30m$color %-17s," "$(echo ${i} | sed -e 's/\/dev\///')" "$temp $clear")"
if [ $(($k % $COLUMNS)) -eq 0 ]; then
out+="\n"
fi
fi
done
out+="\n"
echo
echo -e "HDD Temps:"
printf "$out" | column -c $k -ts $',' | sed -e 's/^/ /'
printf "\n HDD Temps:\n"
printf "$out" | column -c $k -ts $',' | sed -e 's/^/ /'

View File

@@ -9,35 +9,41 @@ red="\e[1;31m"
undim="\e[0m"
declare -A services
services["docker"]="Docker"
#services["openvpn-server@server"]="OVPN server"
#services["openvpn-server@private"]="OVPN private"
services["smbd"]="Samba"
services["smartd"]="Smart"
# services["minecraft@iis"]="MC IIS"
# services["minecraft@iis_creative"]="IIS CREATIVE"
#services["lavalink"]="Lavalink"
#services["discord-music"]="Dis music"
#services["discord-pisya"]="Dis pisya"
#services["discord-boom"]="Dis boom"
services["smbd"]="Samba"
services["nmbd"]="NetBIOS"
services["wsdd"]="WSD"
# sort services
services["isc-dhcp-relay"]="DHCP Relay"
# Sorting associated array
names=$(
for name in ${!services[@]}; do
echo "${services[$name]}:::$name"
done | sort | awk -F::: '{print $2}'
)
k=0
out=""
for i in "${!services[@]}"; do
((k++))
for name in $names; do
VAL=${services[$name]}
((k++))
# color green if service is active, else red
service_status=($(systemctl is-active "$i"))
service_status=($(systemctl is-active "$name"))
if [[ "${service_status}" == "active" ]]; then
out+="${services[$i]}:,${green} up${undim},"
_tmp=$(printf "%-13s %-16s," "${services[$name]}:" "${green}up${undim}")
out+="${_tmp},"
else
out+="${services[$i]}:,${red}down${undim},"
_tmp=$(printf "%-13s %-16s," "${services[$name]}:" "${red}down${undim}")
out+="${_tmp},"
fi
# insert \n every $COLUMNS column
if [ $((($k) % $COLUMNS)) -eq 0 ]; then
out+="\n"
fi
done
out+="\n"
printf "\nservices:\n"
printf "\nServices:\n"
printf "$out" | column -ts $',' | sed -e 's/^/ /'

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 ""