以下のスクリプトでSARを使用しており、Nagiosを監視するためにさまざまなサーバーで実行しようとしています。誰もが以下の確認でスワップ警告を受け取り、スワップしきい値を取得する方法を提案できますか?各サーバーで次のコマンドを実行しながら動的に計算してみましたが、エラーが発生します。
(交換警告/緊急必要性はそれぞれ総交換の20%/総交換の40%と計算されます)
提案してください。
# 2 = CRITICAL (SWAP usage higher than CRITICAL)
# 3 = UNKNOWN (Wrong usage)
SWAP_WARN=
SWAP_CRIT=
SWAPOUT_ACTIVITY_TEST=
## GET SWAP Warning and Critical values from the Machine
# 2 = CRITICAL (SWAP usage higher than CRITICAL)
# 3 = UNKNOWN (Wrong usage)
SWAP_WARN=
SWAP_CRIT=
SWAPOUT_ACTIVITY_TEST=
**## GET SWAP Warning and Critical values from the Machine
temp=$(swapon -s | tail -n 1 | awk '{print $3}' )
SWAP_WARN=$(echo '$(temp)*.20' | bc)
SWAP_CRIT=$(echo '$(temp)*.40' | bc)**
## FETCH ARGUMENTS
##while getopts "h:" OPTION; do
# case "${h}" in
# h)
# usage
# exit 3
# ;;
# ?)
# usage
# exit 3
# ;;
# esac
#done
## CHECK ARGUMENTS
if [ -z ${SWAP_WARN} ] || [ -z ${SWAP_CRIT} ] || [ ${SWAP_WARN} -gt ${SWAP_CRIT} ] ; then
usage
exit 3
fi
## GET SWAP INFO FROM MACHINE
cd /var/log/sa
FOR_VALUE=sa
FOR_DATE=$(date | awk '{print $3}')
SA=$FOR_VALUE$FOR_DATE
SWAPOUT_ACTIVITY_TEST=$(sar -S -f $SA | tail -n 2| head -n 1 | awk '{print $4}')
## CHECK SWAPPING ON MACHINE
if [ ${SWAPOUT_ACTIVITY_TEST} -lt ${SWAP_WARN} ]; then
## SWAP IS OK
LINE="OK! Swapout size in last 10 minutes : ${SWAPOUT_ACTIVITY_TEST} | swapout_size=${SWAPOUT_ACTIVITY_TEST}B;${SWAP_WARN};${SWAP_CRIT};"
echo $LINE
exit 0
elif [ ${SWAPOUT_ACTIVITY_TEST} -gt ${SWAP_WARN} ] && [ ${SWAPOUT_ACTIVITY_TEST} -lt ${SWAP_CRIT} ] || [ ${SWAPOUT_ACTIVITY_TEST} -eq ${SWAP_WARN} ]; then
## SWAP IS IN WARNING STATE
LINE="WARNING! Swapout size in last 10 minutes: ${SWAPOUT_ACTIVITY_TEST} | swapout_size=${SWAPOUT_ACTIVITY_TEST}B;${SWAP_WARN};${SWAP_CRIT};"
:
## FETCH ARGUMENTS
##while getopts "h:" OPTION; do
# case "${h}" in
# h)
# usage
# exit 3
# ;;
# ?)
# usage
# exit 3
# ;;
# esac
#done
## CHECK ARGUMENTS
if [ -z ${SWAP_WARN} ] || [ -z ${SWAP_CRIT} ] || [ ${SWAP_WARN} -gt ${SWAP_CRIT} ] ; then
usage
exit 3
fi
## GET SWAP INFO FROM MACHINE
cd /var/log/sa
FOR_VALUE=sa
FOR_DATE=$(date | awk '{print $3}')
SA=$FOR_VALUE$FOR_DATE
SWAPOUT_ACTIVITY_TEST=$(sar -S -f $SA | tail -n 2| head -n 1 | awk '{print $4}')
## CHECK SWAPPING ON MACHINE
if [ ${SWAPOUT_ACTIVITY_TEST} -lt ${SWAP_WARN} ]; then
## SWAP IS OK
LINE="OK! Swapout size in last 10 minutes : ${SWAPOUT_ACTIVITY_TEST} | swapout_size=${SWAPOUT_ACTIVITY_TEST}B;${SWAP_WARN};${SWAP_CRIT};"
echo $LINE
exit 0
elif [ ${SWAPOUT_ACTIVITY_TEST} -gt ${SWAP_WARN} ] && [ ${SWAPOUT_ACTIVITY_TEST} -lt ${SWAP_CRIT} ] || [ ${SWAPOUT_ACTIVITY_TEST} -eq ${SWAP_WARN} ]; then
## SWAP IS IN WARNING STATE
LINE="WARNING! Swapout size in last 10 minutes: ${SWAPOUT_ACTIVITY_TEST} | swapout_size=${SWAPOUT_ACTIVITY_TEST}B;${SWAP_WARN};${SWAP_CRIT};"
答え1
check_swap
利用できない特別な理由ナギオスプラグイン?
check_swap -w 80% -c 60%
主張したら、sar
なぜしきい値の絶対値を計算するのですか?%swpused
列の値のみを使用して検査の状態を判断することはできませんか?
SWPUSED=$(sar -S -f $SA | tail -2 | head -1 | awk '{print $5}')
SWPUSED_ROUNDED=$(printf "%.0f" $SWPUSED)
if [ $SWPUSED_ROUNDED -gt 40 ]; then
echo "CRITICAL: ${SWPUSED}% of swap space used"
exit 2
elif [ $SWPUSED_ROUNDED -gt 20 ]; then
echo "WARNING: ${SWPUSED}% of swap space used"
exit 1
else
echo "OK: ${SWPUSED}% of swap space used"
exit 0
fi