check_linux_stats插件用于监控linux系统性能(cpu, mem, load, disk usage, disk io, network usage, open files and processes).

需要安装Sys::Statistics::Linux(是perl插件)
nagios插件地址:http://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_linux_stats/details

下载check_linux_stats.pl插件,放置nagios的插件目录,给予执行权限。
perl插件安装:
wget -c http://search.cpan.org/CPAN/authors/id/B/BL/BLOONIX/Sys-Statistics-Linux-0.66.tar.gz
之前测试时版本是0.60,如下

tar xzvf Sys-Statistics-Linux-0.60.tar.gz 
cd Sys-Statistics-Linux-0.60
ls
more INSTALL 
perl Makefile.PL 
yum install perl-UNIVERSAL-require.noarch
perl Makefile.PL 
make
make test
make install

定义nagios命令

define command{
        command_name   linux_cpu_stats
        command_line   $USER1$/check_linux_stats.pl -C -w 100 -s 5
}

define command{
        command_name   linux_load_stats
        command_line   $USER1$/check_linux_stats.pl -L -w 10,8,5 -c 20,18,15
}

define command{
        command_name   linux_mem_stats
        command_line   $USER1$/check_linux_stats.pl -M -w 99,50 -c 100,50
}

define command{
        command_name   linux_disk_stats
        command_line   $USER1$/check_linux_stats.pl -D -w 10 -c 5 -p / -u GB
}

define command{
        command_name   linux_disk_IO_stats
        command_line   $USER1$/check_linux_stats.pl -I -w 100,70 -c 150,100 -p sda1
}

define command{
        command_name   linux_network_stats
        command_line   $USER1$/check_linux_stats.pl -N -w 30000 -c 45000 -p eth0
}

define command{
        command_name   linux_openfiles_stats
        command_line   $USER1$/check_linux_stats.pl -F -w 10000,150000 -c 15000,250000
}

define command{
        command_name   linux_sockets_stats
        command_line   $USER1$/check_linux_stats.pl -S -w 1000 -c 2000
}

define command{
        command_name   linux_process_stats
        command_line   $USER1$/check_linux_stats.pl -P -w 2000 -c 3000
}


定义nagios主机服务

define service{
        use                             local-service
        host_name                       local
        service_description             linux disk stats
        check_command                   linux_disk_stats
        }
        
define service{
        use                             local-service
        host_name                       local
        service_description             linux Processes stats
        check_command                   linux_process_stats
        }
define service{
        use                             local-service
        host_name                       local
        service_description             linux Load stats
        check_command                   linux_load_stats
        }
define service{
        use                             local-service
        host_name                       local
        service_description             linux mem stats
        check_command                   linux_mem_stats
        notifications_enabled           1
        }

define service{
        use                             local-service
        host_name                       local
        service_description             linux cpu stats
        check_command                   linux_cpu_stats
        notifications_enabled           1
        }

define service{
        use                             local-service
        host_name                       local
        service_description             linux socket stats
        check_command                   linux_sockets_stats
        notifications_enabled           1
        }

define service{
        use                             local-service
        host_name                       local
        service_description             linux disk_io stats
        check_command                   linux_disk_IO_stats
        notifications_enabled           1
        }

define service{
        use                             local-service
        host_name                       local
        service_description             linux network stats
        check_command                   linux_network_stats
        notifications_enabled           1
        }

define service{
        use                             local-service
        host_name                       local
        service_description             linux openfiles stats
        check_command                   linux_openfiles_stats
        notifications_enabled           1
        }

[root@localhost objects]# ../../libexec/check_linux_stats.pl -h
check_linux_stats v1.1
Usage: ../../libexec/check_linux_stats.pl -H <host> [-C|-P|-M|-N|-D|-I|-L|-F|-S] [-P  ] -w -c [-s] [-h] [-V]
        -h, --help
                print this help message
        -C, --cpu
                check cpu usage
        -P, --proc
                check the processes number
        -M, --memory
                check memory usage (memory used, swap used and memory cached)
        -N, --network=NETWORK USAGE
                check network usage in resq or bytes (default bytes)
        -D, --disk=DISK USAGE
                check disk usage
        -I, --io=DISK IO USAGE
                check disk I/O (r/w on /dev/sd*)
        -L, --load=LOAD AVERAGE
                check load average
        -F, --file=FILE STATS
                check open files (file alloc, inode alloc)
        -S, --socket=SOCKET STATS
                socket usage (tcp, udp, raw)
        -p, --pattern
                eth0,eth1...sda1,sda2.../usr,/tmp
        -w, --warning
                warning thresold
        -c, --critical
                critical thresold
        -s, --sleep
                default 1 sec.
        -u, --unit
               %, KB, MB or GB left on disk usage, default : MB
               REQS OR BYTES on disk io statistics, default : REQS
        -V, --version
                version number

        ex : 
        * Cpu usage     :
                ./check_linux_stats.pl -C -w 90 -c 100 -s 5
                        CPU OK : idle 99.80% | USER1=0.00% system=0.20% iowait=0.00% idle=99.80%;90;100

        * Load average  : 
                ./check_linux_stats.pl -L -w 10,8,5 -c 20,18,15
                        LOAD AVERAGE OK : 0.20,0.07,0.16 | load1=0.20;10;20;0 load5=0.07;8;18;0 load15=0.16;5;15;0

        * Memory usage  :
                ./check_linux_stats.pl -M -w 99,50 -c 100,50
                        MEMORY OK : used 94.52% |MemUsed=94.52%;99;100 SwapUsed=0.01;50;50 MemCached=39.66

        * Disk usage    :
                ./check_linux_stats.pl -D -w 10 -c 5 -p /,/usr,/tmp,/var
                        DISK WARNING used :  / 3331.80MB on 3875.09MB (8.86% free) /usr 10084.27MB on 14528.41MB (25.43% free)| /=3331.80MB /usr=10084.27MB

        * Disk I/O      :
                ./check_linux_stats.pl -I -w 100,70 -c 150,100 -p sda1,sda2,sda4
                        DISK I/O OK | sda2_read=0.00;100;150 sda2_write=0.00;70;100 sda4_read=0.00;100;150 sda4_write=0.00;70;100 sda1_read=0.00;100;150 sda1_write=0.00;70;100

        * Network usage :
                ./check_linux_stats.pl -N -w 30000 -c 45000 -p eth0
                        NET USAGE OK eth0:8021.78KB  | eth0_txbyt=3461.39KB eth0_txerrs=0.00KB eth0_rxbyt=4560.40KB eth0_rxerrs=0.00KB

        * Open files    :
                ./check_linux_stats.pl -F -w 10000,150000 -c 15000,250000
                        OPEN FILES OK allocated: 1728 (inodes: 70390) | fhalloc=1728;10000;15000;411810 inalloc=70390;150000;250000;100250 dentries=50754

        * Socket usage  :
                ./check_linux_stats.pl -S -w 1000 -c 2000
                        SOCKET USAGE  OK : used 257 |used=257;1000;2000 tcp=18 udp=5 raw=0

        * Number of procs       :
                ./check_linux_stats.pl -P -w 1000 -c 2000
                        PROCS OK : count 272 |count=272;1000;2000 runqueue=2 blocked=0 running=2 new=0.98

        * Process mem & cpu     :
                ./check_linux_stats.pl -T -w 9551820 -c 9551890 -p /var/run/jonas.pid
                        PROCESSES OK  | java_vsize=1804918784;2000000000;3000000000 java_nswap=0 java_cnswap=0 java_cpu=0


/usr/local/nagios/libexec/check_linux_stats.pl -C -w 90 -c 100 -s 5
/usr/local/nagios/libexec/check_linux_stats.pl -L -w 10,8,5 -c 20,18,15
/usr/local/nagios/libexec/check_linux_stats.pl -M -w 99,50 -c 100,50
/usr/local/nagios/libexec/check_linux_stats.pl -D -w 10 -c 5 -p /,/usr,/tmp,/var
/usr/local/nagios/libexec/check_linux_stats.pl -I -w 100,70 -c 150,100 -p sda1,sda2,sda4
/usr/local/nagios/libexec/check_linux_stats.pl -N -w 30000 -c 45000 -p eth0
/usr/local/nagios/libexec/check_linux_stats.pl -F -w 10000,150000 -c 15000,250000
/usr/local/nagios/libexec/check_linux_stats.pl -S -w 1000 -c 2000
/usr/local/nagios/libexec/check_linux_stats.pl -P -w 1000 -c 2000
/usr/local/nagios/libexec/check_linux_stats.pl -T -w 9551820 -c 9551890 -p /var/run/jonas.pid


2 thoughts on “nagios插件脚本check_linux_stats”

  1. Ι ωas suggеsteԁ this ωeb site
    by my cοusin. I am not sure whether
    thiѕ post is written bу hіm аs no one else knoω such ԁetailed аbout
    my difficulty. You аre wonderful! Thanks!

发表评论

电子邮件地址不会被公开。 必填项已用*标注