728x90
#### CPU Usage 확인
1. cpu check할 서버에서 check_cpu 생성
cd /usr/local/nagios/libexec
vi check_cpu
#!/bin/bash
function usage {
echo "$(basename $0) usage: "
echo " -w warning_level Example: 80"
echo " -c critical_level Example: 90"
echo ""
exit 1
}
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-w)
WARN="$2"
shift
;;
-c)
CRIT="$2"
shift
;;
*)
usage
shift
;;
esac
shift
done
[ ! -z ${WARN} ] && [ ! -z ${CRIT} ] || usage
CPU_USAGE="$(vmstat 1 2|tail -1)"
CPU_USER="$(echo ${CPU_USAGE} | awk '{print $13}')"
CPU_SYSTEM="$(echo ${CPU_USAGE} | awk '{print $14}')"
CPU_IDLE="$(echo ${CPU_USAGE} | awk '{print $15}')"
CPU_IOWAIT="$(echo ${CPU_USAGE} | awk '{print $16}')"
CPU_ST="$(echo ${CPU_USAGE} | awk '{print $17}')"
CPU_TUSAGE=`expr $CPU_USER + $CPU_SYSTEM`
if [[ ${CPU_USER} -gt ${CRIT} || ${CPU_SYSTEM} -gt ${CRIT} || ${CPU_IOWAIT} -gt ${CRIT} || ${CPU_ST} -gt ${CRIT} ]]
then
echo "CRITICAL - CPU Usage ${CPU_TUSAGE} 퍼센트 | CPU_USER=${CPU_USER};;;; CPU_SYSTEM=${CPU_SYSTEM};;;; CPU_IDLE=${CPU_IDLE};;;; CPU_IOWAIT=${CPU_IOWAIT};;;; CPU_ST=${CPU_ST};;;;"
exit 2
elif [[ ${CPU_USER} -gt ${WARN} || ${CPU_SYSTEM} -gt ${WARN} || ${CPU_IOWAIT} -gt ${WARN} || ${CPU_ST} -gt ${WARN} ]]
then
echo "WARNING - CPU Usage ${CPU_TUSAGE} 퍼센트 | CPU_USER=${CPU_USER};;;; CPU_SYSTEM=${CPU_SYSTEM};;;; CPU_IDLE=${CPU_IDLE};;;; CPU_IOWAIT=${CPU_IOWAIT};;;; CPU_ST=${CPU_ST};;;;"
exit 1
else
echo "OK - CPU Usage ${CPU_TUSAGE} 퍼센트 | CPU_USER=${CPU_USER};;;; CPU_SYSTEM=${CPU_SYSTEM};;;; CPU_IDLE=${CPU_IDLE};;;; CPU_IOWAIT=${CPU_IOWAIT};;;; CPU_ST=${CPU_ST};;;;"
exit 0
fi
chmod +x ./check_cpu
chown nagios:nagios ./check_cpu
### nrpe 등록
vi /usr/local/nagios/etc/nrpe.cfg
command[check_cpu]=/usr/local/nagios/libexec/check_cpu -w 50 -c 60
## nrpe 재시작
systemctl restart nrpe
2. Nagios Server Service 등록
vi /usr/local/nagios/etc/object/service.cfg
define service {
use generic-service
host_name test-server
service_description CPU Usage
check_command check_nrpe!check_cpu
}
## Nagios Server Restart
systemctl restart nagios
'Linux > Nagios' 카테고리의 다른 글
Nagios check memory (0) | 2023.12.23 |
---|---|
모니터링 대상 서버 nagios agent 설치 및 nrpe 설치 (0) | 2023.12.23 |
Nagios Server 설치 (0) | 2023.12.23 |
nagios plugin, nrpe yum 설치 (0) | 2023.12.23 |