아래 스크립트에서 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