Refactor CPU load

Use a single function name for collecting loadavg. Reduces pollution
(issue #28).
Refactor _lp_load_color: less code but same features.
This commit is contained in:
Olivier Mengué 2012-08-15 00:11:34 +02:00
parent 7f5346f953
commit 2a833475bc

View File

@ -153,27 +153,26 @@ esac
# get current load
_lp_load_Linux()
{
local load
load=$(awk '{print $1}' /proc/loadavg)
echo -n "$load"
}
_lp_load_FreeBSD()
{
local load
load=$(LANG=C sysctl -n vm.loadavg | awk '{print $2}')
echo -n "$load"
}
_lp_load_SunOS()
{
local load
load=$(LANG=C uptime | awk '{print substr($10,0,length($10))}')
echo -n "$load"
}
case "$LP_OS" in
Linux)
_lp_cpu_load () {
local load eol
read load eol < /proc/loadavg
echo "$load"
}
;;
FreeBSD)
_lp_cpu_load () {
local bol load eol
read bol load eol < $<( LANG=C sysctl -n vm.loadavg )
echo "$load"
}
;;
SunOS)
_lp_cpu_load () {
LANG=C uptime | awk '{print substr($10,0,length($10))}'
}
esac
#################
@ -787,14 +786,9 @@ _lp_load_color()
# Then we have to choose the values at which the colours switch, with
# anything past yellow being pretty important.
local loadval
local load
loadval=$(_lp_load_$LP_OS)
load=$(echo $loadval | sed 's/\.//g;s/^0*//g' )
if [[ -z "$load" ]] ; then
load=0
fi
let "load=$load/$_lp_CPUNUM"
load="$(_lp_cpu_load | sed 's/\.//g;s/^0*//g' )"
let "load=${load:-0}/$_lp_CPUNUM"
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
then