#!/bin/bash
# fixme: can this be a library?
# normal
WHT='\033[0;37m'
RED='\033[0;31m'
YEL='\033[0;33m'
GRN='\033[0;32m'
BLU='\033[0;34m'
PUR='\033[0;35m'
# Bold
BWHT='\033[1;37m'
BRED='\033[1;31m'
BYEL='\033[1;33m'
BGRN='\033[1;32m'
BBLU='\033[1;34m'
BPUR='\033[1;35m'
# underlines
UWHT='\033[4;37m'
URED='\033[4;31m'
UYEL='\033[4;33m'
UGRN='\033[4;32m'
UBLU='\033[4;34m'
UPUR='\033[4;35m'
# reset
RST='\033[0m'
clear
echo $RST
echo "${UWHT}CPU STUFF"
echo $RST
#CPU=`cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{printf "%.2f%\n", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'`
#CPU=`ps -A -o pcpu | tail -n+2 | paste -sd+ | bc`
#echo "${PUR}$CPU${BWHT} (CURRENT CPU %)"
# apt install python3-pip
# python3 -m pip install psutil
printf "%b" \
"\
import psutil\n\
cpu_percent_cores = psutil.cpu_percent(interval=2, percpu=True)\n\
avg = sum(cpu_percent_cores)/len(cpu_percent_cores)\n\
cpu_percent_total_str = ('%.2f' % avg) + '%'\n\
cpu_percent_cores_str = [('%.2f' % x) + '%' for x in cpu_percent_cores]\n\
print('Total: {}'.format(cpu_percent_total_str))\n\
print('Individual CPUs: {}'.format(' '.join(cpu_percent_cores_str)))\n\
" | python3
echo $RST
ps -e -o pcpu,pmem,args --sort=-pcpu | head -n 11
#ps aux | sort -nrk 3,3 | head -n 11
echo $RST
echo "${UWHT}MEMORY STUFF"
echo $RST
APACHE2=`ps -ylC apache2 | awk '{x += $8;} END {print x/1024}'`
MYSQLD=`ps -ylC mariadbd | awk '{x += $8;} END {print x/1024}'`
AVAIL=`cat /proc/meminfo | grep MemAvailable | awk '{x += $2} END {print x/1024; }'`
SWAP=`free -m | grep Swap | awk '{x += $3;} END {print x}'`
echo "${PUR}$APACHE2${BWHT} (APACHE2)"
echo "${PUR}$MYSQLD${BWHT} (MARIADB)"
echo "${PUR}$AVAIL${BWHT} (AVAILABLE)"
echo "${PUR}$SWAP${BWHT} (SWAP USED)"
echo $RST
ps -e -o pcpu,pmem,args --sort=-pmem | head -n 11
#ps aux --sort -rss | head -11
echo $RST
echo "${UWHT}DISK/NETWORK STUFF"
echo $RST
echo "${PUR}(SPACE)${BWHT}"
echo $RST
df -h
echo $RST
echo "${PUR}(INODES)${BWHT}"
echo $RST
df -hi
echo $RST
# apt install dstat
dstat -drn --socket 1 5