28 lines
931 B
Bash
Executable file
28 lines
931 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
. ~/bin/i3blocks/_utils
|
|
|
|
# Get total memory usage and show highest consumer
|
|
mem(){
|
|
local memused=$(free | grep Mem | awk '{printf "%.0f\n", $3/$2 * 100.0}')
|
|
local memproc=$(basename "$(ps --no-headers -A --sort -rss -o cmd | head -1 | awk {'print $1'})")
|
|
if [[ $(echo "$memused >= 50" | bc -l ) == "1" ]] && [[ $(echo "$memused < 60" | bc -l ) == "1" ]]; then
|
|
local bg=$warn1_bg
|
|
local fg=$warn1_fg
|
|
elif [[ $(echo "$memused >= 60" | bc -l ) == "1" ]] && [[ $(echo "$memused < 70" | bc -l ) == "1" ]]; then
|
|
local bg=$warn2_bg
|
|
local fg=$warn2_fg
|
|
elif [[ $(echo "$memused >= 70" | bc -l ) == "1" ]]; then
|
|
local bg=$crit_bg
|
|
local fg=$crit_fg
|
|
fi
|
|
local stat="MEM ${memused}% [$memproc]"
|
|
|
|
if [[ -n "$bg" ]]; then
|
|
echo -e " <span background=\"$bg\" color=\"$fg\"> $stat </span> \n"
|
|
else
|
|
echo -e "$stat\n"
|
|
fi
|
|
}
|
|
|
|
mem
|