Nagios check CPU used?
Nagios check CPU used là việc sử dụng một file script để kiểm tra tình trạng hoat động của CPU trên server. Qua đó sẽ cho ta biết các thông tin về số CPU đã sử dụng. Kiểm tra CPU trên server cũng là một việc quan trọng, giúp server hoạt động ổn định và trơn tru.
Bài viết trước mình đã hướng dẫn các bạn cách kiểm tra memory used. Bài viết này sẽ tiếp tục hướng dẫn các bạn cách sử dụng Nagios check CPU used.
Hướng dẫn thực hiện.
1. Trên server cần kiểm tra CPU.
Bạn tải file check_cpu_usage.sh tại đây và bỏ vào thư mục /usr/local/nagios/libexec/
Hoặc bạn có thể tạo file check_cpu_usage.sh trong thư mục /usr/local/nagios/libexec/
và thêm vào nội dung sau:
#!/bin/sh
# Version 0.2
#
# ### History ###
# V0.1 Created script from CPU Idle script
# V0.2 Handle dicimal compare and output
if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ] ; then
warn=$2
crit=$4
IDLE=`top -b -n2|grep Cpu|tail -1|cut -d',' -f4|cut -d% -f1`
USAGE=`echo "100 - $IDLE"|bc|sed -r 's/^\./0./g'` ||exit 3
# echo "DEBUG: head: ${USAGE%%.*} tail: ${USAGE##*.} "
# echo "DEBUG: ||$USAGE_RAW|| , ||$USAGE||"
if [ $warn -lt ${USAGE%%.*} ];then
if [ $crit -lt ${USAGE%%.*} ]; then
echo "CRITICAL - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
exit 2
else
echo "WARNING - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
exit 1
fi
else
echo "OK - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
exit 0
fi
else
echo "$0 - Nagios Plugin for checking CPU Usage in percentage "
echo ""
echo "Usage: $0 -w <warnlevel> -c <critlevel>"
echo " = warnlevel and critlevel is warning and critical value for alerts. "
echo ""
echo "EXAMPLE: /usr/lib64/nagios/plugins/$0 -w 80 -c 90 "
echo " = This will send warning alert when CPU Usage percentage is higher than 80%, and send critical when higher than 90%"
echo ""
exit 3
fi
Chỉnh sữa file nrpe.cfg.
Tìm đến file usr/local/nagios/etc/nrpe.cfg
Bên dưới dòng # The following examples use hardcoded command arguments…
Bạn thêm nội dung sau:
command[check_cpu]=/usr/local/nagios/libexec/check_cpu_usage.sh -w 90 -c 95
Chú thích:
[check_cpu] là tên mình sẽ gọi trên Nagios Monitoring Server.
check_cpu_usage.sh là tên file script mình tạo.
-w 90 là nagios sẽ đưa ra cảnh báo warning khi lượng CPU sử dụng trên 90%.
-c 95 là nagios sẽ đưa ra cảnh báo critical khi lượng CPU sử dụng trên 95%.
2. Cài đặt trên Nagios Monitoring Server.
Chỉnh sữa file service.cfg nằm trong usr/local/nagios/etc/service.cfg
Thêm vào nội dung sau:
define service {
use generic-service
host_name codegiday
service_description Check CPU
check_command check_nrpe!check_cpu
notifications_enabled 1
}
Restart service Nagios.
service nagios restart
Kiểm tra hoạt động.
http://ip-server-nagios/nagios
Kết luận:
Mình vừa giới thiệu đến các bạn cách kiểm tra CPU sử dụng vào Nagios Monitoring Server. Các bạn có thắc mắc gì có thể để lại comment chia sẽ bên dưới. Nếu bài viết có nhiều sai sót xin các bạn góp ý
Cảm ơn các bạn theo dõi.
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you!
However, how can we communicate?
It’s wonderful that you are getting thoughts from this article as well as from our dialogue made at this place.
Great items from you, man. I have consider your stuff prior to and you’re just too excellent.
I really like what you’ve got here, really like what you’re
saying and the best way in which you say it. You are making it entertaining and you still take care of to keep it wise.
I can not wait to read much more from you. This is actually a wonderful web site.
Also visit my web blog; онлайн заявка на кредит авто
Pretty! This was an extremely wonderful article. Thank
you for supplying this information.