nagios check cpu used sub

Hướng dẫn sử dụng Nagios check CPU used

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.

30 thoughts to “Hướng dẫn sử dụng Nagios check CPU used”

  1. I have been exploring for a bit for any high-quality articles or weblog posts on this kind of house .

    Exploring in Yahoo I ultimately stumbled upon this site.
    Reading this info So i am glad to show that I have an incredibly good uncanny feeling I found out exactly what I needed.
    I such a lot unquestionably will make sure to do not overlook
    this web site and give it a look on a relentless basis.

  2. Hi there! Someone in my Facebook group shared this site with us so I came to give it a look.
    I’m definitely loving the information. I’m book-marking and will be
    tweeting this to my followers! Wonderful blog and
    terrific design.

  3. Howdy I am so grateful I found your blog page, I really found you by
    mistake, while I was searching on Digg for something else, Regardless I am
    here now and would just like to say many thanks for a tremendous post and a all round entertaining blog (I also love
    the theme/design), I don’t have time to read through it all at the minute but I have saved it and also added in your RSS feeds, so when I have
    time I will be back to read more, Please do keep up the great jo.

  4. you’re in reality a excellent webmaster. The web site loading pace is incredible.
    It seems that you’re doing any distinctive trick.
    Also, The contents are masterwork. you’ve done a excellent activity on this
    matter!

  5. I like the helpful information you provide in your articles.
    I will bookmark your weblog and take a look at once more here frequently.
    I’m reasonably sure I will learn a lot of new stuff proper right here!
    Best of luck for the following!

  6. Hey! This is kind of off topic but I need some help from an established blog.
    Is it very difficult to set up your own blog?
    I’m not very techincal but I can figure
    things out pretty fast. I’m thinking about setting up my own but I’m not sure where to begin. Do you have
    any points or suggestions? Cheers

  7. An outstanding share! I’ve just forwarded this onto a colleague who
    was doing a little homework on this. And he in fact bought me lunch because
    I discovered it for him… lol. So allow me to reword this….

    Thank YOU for the meal!! But yeah, thanks for spending time to discuss this matter here
    on your internet site.

  8. Having read this I believed it was rather informative.
    I appreciate you taking the time and effort to
    put this informative article together. I once again find myself personally spending
    a significant amount of time both reading and posting comments.

    But so what, it was still worth it!

  9. Hey there would you mind stating which blog platform you’re
    working with? I’m going to start my own blog soon but I’m having a difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different
    then most blogs and I’m looking for something completely unique.
    P.S My apologies for being off-topic but I had to ask!

  10. I’m not sure exactly why but this site is loading very slow for me.
    Is anyone else having this issue or is it a problem on my end?
    I’ll check back later on and see if the problem still exists.

  11. Fantastic items from you, man. I’ve understand your stuff prior to and you’re just
    extremely magnificent. I actually like what
    you have received here, certainly like what
    you’re stating and the way through which you are saying it.
    You’re making it entertaining and you continue
    to care for to keep it sensible. I cant wait to read
    far more from you. That is actually a great web site.

Comments are closed.