initial script
This commit is contained in:
55
load_per_cpu.sh
Executable file
55
load_per_cpu.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
WARNING=( 8 5 2 )
|
||||
CRITICAL=( 10 8 3 )
|
||||
while test $# -gt 0; do
|
||||
case $1 in
|
||||
(-h|--help) cat <<EOF
|
||||
$0 [OPTIONS]
|
||||
|
||||
OPTIONS
|
||||
|
||||
-w, --warning "a b c" set warning threshold for:
|
||||
a: 1min, b: 5min, c: 15min average
|
||||
(default: ${WARNING[@]})
|
||||
-c, --critical "a b c" set critical threshold for:
|
||||
a: 1min, b: 5min, c: 15min average
|
||||
(default: ${CRITICAL[@]})
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Icinga plugin to check load average per CPU. Shows 1min, 5min 15min
|
||||
average per CPU. Different to check_load, the load is divided by the
|
||||
number of CPU units and therefore normalized. So the same warning and
|
||||
critical levels fit for any server.
|
||||
|
||||
EOF
|
||||
exit;;
|
||||
(-w|--warning) shift; WARNING=( $1 );;
|
||||
(-c|--critical) shift; CRITICAL=( $1 );;
|
||||
esac
|
||||
if test $# -lt 1; then
|
||||
echo "ERROR: missing option, try $0 --help"
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
a=( $(cut -d' ' -f 1-3 </proc/loadavg) )
|
||||
|
||||
echo "before ${a[@]}"
|
||||
level=0
|
||||
txt=OK
|
||||
for ((i=0;i<3;++i)); do
|
||||
a[$i]=$(bc -l <<< "${a[$i]}/$(nproc)")
|
||||
if test $level -lt 1 -a $(bc -l <<< "${a[$i]}>${WARNING[$i]}") -eq 1; then
|
||||
level=1
|
||||
txt=WARNING
|
||||
fi
|
||||
if test $level -lt 2 -a $(bc -l <<< "${a[$i]}>${CRITICAL[$i]}") -eq 1; then
|
||||
level=2
|
||||
txt=CRITICAL
|
||||
fi
|
||||
done
|
||||
echo $txt - load average: $(printf '%.2f, %.2f, %.2f|load1=%.3f;%.3f;%.3f;0; load5=%.3f;%.3f;%.3f;0; load15=%.3f;%.3f;%.3f;0;' ${a[@]} ${a[0]} ${WARNING[0]} ${CRITICAL[0]} ${a[1]} ${WARNING[1]} ${CRITICAL[1]} ${a[2]} ${WARNING[2]} ${CRITICAL[2]})
|
||||
exit $level
|
Reference in New Issue
Block a user