Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print most RAM consuming procs when memory is critical #85

Merged
merged 3 commits into from
Jun 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions terminal/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,23 @@ printBar()
local max=$2
local size=$3
local crit_percent=$4

local percent=$(($current*100/$max))


## COMPUTE VARIABLES
local num_bars=$(($size * $current / $max))
if [ $num_bars -gt $size ]; then
num_bars=$size
fi
local crit_num_bars=$(($size * $crit_percent / 100))


## SET COLORS
local bar_color=$fc_ok
if [ $num_bars -gt $crit_num_bars ]; then
if [ $percent -gt $crit_percent ]; then
local bar_color=$fc_crit
fi



## PRINT BAR
printf "${fc_deco}[${bar_color}"
i=0
Expand Down Expand Up @@ -277,6 +278,7 @@ printMonitor()
printf "${fc_info}%-${pad}s" "$label"
printBar $current $max $bar_length $crit_percent


if $print_as_percentage; then
per=$(($current*100/$max))
printf " ${fc_highlight}%${bar_num_digits}s${fc_info}%%%%${fc_none}" $per
Expand Down Expand Up @@ -649,6 +651,7 @@ printLastLogins()
printSystemctl()
{
systcl_num_failed=$(systemctl --failed | grep "loaded units listed" | head -c 1)

if [ "$systcl_num_failed" -ne "0" ]; then
local failed=$(systemctl --failed | grep ".service")
printf "${fc_crit}SYSTEMCTL FAILED SERVICES:\n"
Expand All @@ -659,26 +662,49 @@ printSystemctl()



printTop()
printTopCPU()
{
local current=$(awk '{avg_1m=($1)} END {printf "%3.0f", avg_1m}' /proc/loadavg)
local max=$(nproc --all)
local percent=$(awk '{printf "%3.0f\n",$1*100/'"$max"'}' /proc/loadavg)

if [ $percent -gt $crit_cpu_percent ]; then
local top=$('nice' 'top' -b -w 80 -d 1 | head -n 11 | sed 's/%/%%/g')
local load=$(echo "${top}" | head -n 3 | tail -n 1)
local load=$(echo "${top}" | head -n 3 | tail -n 1 | tr '', ' ')
local head=$(echo "${top}" | head -n 7 | tail -n 1)
local proc=$(echo "${top}" | tail -n 4 | grep -v "top")

printf "${fc_crit}SYSTEM LOAD:${fc_info} ${load:9:36}${fc_highlight}\n"
printf "${fc_crit}SYSTEM LOAD:${fc_info} ${load:9:36}\n"
printf "${fc_crit}$head${fc_none}\n"
printf "${fc_info}${proc}${fc_none}\n\n"
fi
}



printTopRAM()
{
local mem_info=$('free' -m | head -n 2 | tail -n 1)
local current=$(echo "$mem_info" | awk '{mem=($2-$7)} END {printf mem}')
local max=$(echo "$mem_info" | awk '{mem=($2)} END {printf mem}')
local percent=$(($current*100/$max))

if [ $percent -gt $crit_ram_percent ]; then
local available=$(echo $mem_info | awk '{print $NF}')
local procs=$(ps --cols=80 -eo pmem,size,pid,cmd --sort=-%mem |\
head -n 4 | tail -n 3 |\
awk '{$2=int($2/1024)"MB";}
{printf("%5s%8s%8s\t%s\n", $1, $2, $3, $4)}')

printf "${fc_crit}MEMORY:\t "
printf "${fc_info}Only ${available} MB of RAM available!!\n"
printf "${fc_crit} %%\t SIZE\t PID\tCOMMANDD\n"
printf "${fc_info}${procs}${fc_none}\n\n"
fi
}






Expand Down Expand Up @@ -734,8 +760,8 @@ local bar_length=13
local crit_cpu_percent=50
local crit_ram_percent=75
local crit_swap_percent=25
local crit_hdd_percent=80
local crit_home_percent=80
local crit_hdd_percent=85
local crit_home_percent=85
local bar_num_digits=5
local info_label_width=16
local cpu_as_percentage=true
Expand Down Expand Up @@ -776,7 +802,8 @@ clear
printHeader
printLastLogins
printSystemctl
printTop
printTopCPU
printTopRAM



Expand Down