Get load average excluding niced processes
You can write up your own script that uses ps
to list all processes in the run/runnable state without a nice value greater than 0. The specific syntax you need to use will differ based on your version of ps
. Something like this may work:
ps -eo state,nice | awk 'BEGIN {c=0} $2<=0 && $1 ~ /R/ { c++ } END {print c-2}'
It runs ps
collecting the state
and nice
level of all processes and pipes the output to awk
which sets a count variable c
and increments it whenever the second column (nice) is less than or equal to 0 and the first column includes R (for runnable). Once it's done it prints out the value of c
after subtracting 2. I subtract 2 because the ps and the awk commands will almost always be considered runnable for the duration of the command's execution. The end result will be a single number which represents the number of processes that were runnable at the time that the script executed excluding itself and processes run nicely
, which is essentially the instantaneous load on the machine. You'd need to run this periodically and average it over 1, 5, and 15 minutes to determine the typical load averages of the machine.