Nagios self-monitoring load due to different types of machines need to distinguish the setting parameters, very inconvenient, use percent can not consider the number of CPU cores of the machine
#!/bin/bash###########################################################[email protected] load_info ##[email protected] ################################ ########################### #set -o nounsetset -o errexitif [ $# -ne 4 ];then echo "sh ' basename $0 ' -w[args] -c[args]" exit 2fiwhile getopts :w:c: optdo case $opt  IN        W) warng _threshold= $OPTARG ;;           C) critical_threshold= $OPTARG ;;         H) echo " Usage:sh $0 -w 80 -c 100 " exit 3 ;; :) echo "option -$OPTARG requires an argument." >&2 exit 3 ;; &nbsP; \?) echo "sh ' basename $0 ' -w[args] -c[args] " exit 3 ;; esac doneif [ -z "$Warng _threshold " ] | | [ -z "$Critical _threshold" ];then# echo "sh ' basename $0 ' -w[args] -c[args] " exit 2fiint_war_threshold=$ (echo $Warng _ threshold|awk ' {print $1*100} ') int_cri_threshold=$ (echo $Critical _threshold|awk ' {print  $1*100} ') load_ok=0load_warning=1load_critical=2load_unknown=3_load_1min=$ (cat /proc/loadavg | awk ' {print $1} ') _load_5min=$ (cat /proc/loadavg |awk ' {print $2} ') _load_15min=$ ( cat /proc/loadavg |awk ' {priNT $3} ') _cpu_core=$ (cat /proc/cpuinfo |grep processor|wc -l) function get_ Percent () { local load_value=$1 #local temp_value=$ (Echo "Scale=4;${load_value}/${_cpu_core}" |BC) #_value =$ (echo "$temp _value*100" |bc|awk ' {printf '%2.2f\n ($} ') local _value=$ (echo "$load _value" |awk ' { printf "%2.2f\n", $1/_cpu_core*100} ' _cpu_core=${_cpu_core}) printf ${_value}} min1_load=$ (Get_percent ${_load_1min}) min5_load=$ (Get_percent ${_load_5min}) min15_load=$ (Get_percent ${_load_15min}) #echo "$min 1_load, $min 5_load, $min 15_load" int_min1_load=$ (Echo $min 1_load|awk ' {print $1*100} ') int_min5_load=$ (echo $min 5_load|awk ' {print $1* int_min15_load=$ (echo $min 15_load|awk ' {print $1*100} ') if [ $int _min1_load -lt $int _war_threshold ] && [ $int _min5_load -lt $int _war_threshold ] && [ $int _min15_load -lt $int _war_threshold ];then echo "OK" exit $load _okelif [ $int _min1_load -gt $int _cri_threshold ] | | [ $int _min5_load -gt $int _cri_threshold ] | | [ $int _min15_load -gt $int _cri_threshold ];then echo "CRITICAL : min1_load:${min1_load},min5_load:${min5_load},min15_load:${min15_load} " exit $ load_criticalelse echo "Warning: min1_load:${min1_load},min5_load:${min5_load}, Min15_load:${min15_load} " exit $load _warningfi
This article from "Xbzy" blog, declined reprint!
Nagios Load Percent monitor alarm plug-in