作者:田逸(formyz)
默认情况下,使用Nrpe插件check_disk加选项“-w”与”-c”除了输出我们想监控的磁盘分区外,还输出了一些形如“/dev/shm”不需要监控的项目(如下图所示),倒对查看起到了一些干扰作用。
从Centreon 或者 Nagios的Web管理后台,也能看到这些造成干扰的输出(如下图所示),最好将这些没有的干扰项排除掉。
登录NRPE所在的宿主系统,执行命令“./check_disk -h”,了解此命令都有哪些选项,其输出如下:
This plugin checks the amount of used disk space on a mounted file system and generates an alert if free space is less than one of the threshold values Usage: check_disk -w limit -c limit [-W limit] [-K limit] {-p path | -x device} [-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ] [-t timeout] [-u unit] [-v] [-X type] [-N type] [-n] Options: -h, --help Print detailed help screen -V, --version Print version information --extra-opts=[section][@file] Read options from an ini file. See https://www.nagios-plugins.org/doc/extra-opts.html for usage and examples. -w, --warning=INTEGER Exit with WARNING status if less than INTEGER units of disk are free -w, --warning=PERCENT% Exit with WARNING status if less than PERCENT of disk space is free -c, --critical=INTEGER Exit with CRITICAL status if less than INTEGER units of disk are free -c, --critical=PERCENT% Exit with CRITICAL status if less than PERCENT of disk space is free -W, --iwarning=PERCENT% Exit with WARNING status if less than PERCENT of inode space is free -K, --icritical=PERCENT% Exit with CRITICAL status if less than PERCENT of inode space is free -p, --path=PATH, --partition=PARTITION Mount point or block device as emitted by the mount(8) command (may be repeated) -x, --exclude_device=PATH <STRING> Ignore device (only works if -p unspecified) -C, --clear Clear thresholds -E, --exact-match For paths or partitions specified with -p, only check for exact paths -e, --errors-only Display only devices/mountpoints with errors -f, --freespace-ignore-reserved Don't account root-reserved blocks into freespace in perfdata -g, --group=NAME Group paths. Thresholds apply to (free-)space of all partitions together -k, --kilobytes Same as '--units kB' -l, --local Only check local filesystems -L, --stat-remote-fs Only check local filesystems against thresholds. Yet call stat on remote filesystems to test if they are accessible (e.g. to detect Stale NFS Handles) -M, --mountpoint Display the mountpoint instead of the partition -m, --megabytes Same as '--units MB' -A, --all Explicitly select all paths. This is equivalent to -R '.*' -R, --eregi-path=PATH, --eregi-partition=PARTITION Case insensitive regular expression for path/partition (may be repeated) -r, --ereg-path=PATH, --ereg-partition=PARTITION Regular expression for path or partition (may be repeated) -I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION Regular expression to ignore selected path/partition (case insensitive) (may be repeated) -i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION Regular expression to ignore selected path or partition (may be repeated) -t, --timeout=INTEGER Seconds before plugin times out (default: 10) -u, --units=STRING Choose bytes, kB, MB, GB, TB (default: MB) -v, --verbose Show details for command-line debugging (Nagios may truncate output) -X, --exclude-type=TYPE Ignore all filesystems of indicated type (may be repeated) -N, --include-type=TYPE Check only filesystems of indicated type (may be repeated) -n, --newlines Multi-line output of each disk's status information on a new line Examples: check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p / Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$' Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex are grouped which means the freespace thresholds are applied to all disks together check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M Send email to help@nagios-plugins.org if you have questions regarding use of this software. To submit patches or suggest improvements, send email to devel@nagios-plugins.org |
选项大写的“-X”,作用是排除某个文件系统,这里我们尝试使用这个选项,加参数tmpfs,查看其输出。
[root@php8-83 ~]# /usr/local/nrpe/libexec/check_disk -w 20% -c 10% -X tmpfs DISK OK - free space: /dev 3850 MB (100.00% inode=100%); / 23109 MB (27.18% inode=84%); /boot 720 MB (79.28% inode=99%);| /dev=0MB;3080;3465;0;3850 /=61891MB;71658;80615;0;89573 /boot=188MB;780;877;0;975 |
把加选项“-X”与不加选项“-X”两相对比(如下图所示),确实过滤掉了一些干扰项。
看起来还不完美,还有“/dev”这样的没什么意义的输出,看能不能把它也过滤掉。还有一个选项小写的“-x”,用它来试试。
单独用“-x”这个选项,后加“/dev”,输出如下:
[root@php8-83 ~]# /usr/local/nrpe/libexec/check_disk -w 20% -c 10% -x /dev DISK OK - free space: /dev/shm 3862 MB (100.00% inode=100%); /run 3485 MB (90.24% inode=100%); /sys/fs/cgroup 3862 MB (100.00% inode=100%); / 23099 MB (27.17% inode=84%); /boot 720 MB (79.28% inode=99%); /run/user/0 772 MB (100.00% inode=100%);| /dev/shm=0MB;3089;3475;0;3862 /run=376MB;3089;3475;0;3862 /sys/fs/cgroup=0MB;3089;3475;0;3862 /=61902MB;71658;80615;0;89573 /boot=188MB;780;877;0;975 /run/user/0=0MB;617;694;0;772 |
根本没起作用,那么将选项“-X”与其一起使用,会怎么样?
[root@php8-83 ~]# /usr/local/nrpe/libexec/check_disk -w 20% -c 10% -x /dev -X tmpfs DISK OK - free space: / 23095 MB (27.17% inode=84%); /boot 720 MB (79.28% inode=99%);| /=61905MB;71658;80615;0;89573 /boot=188MB;780;877;0;975 |
仅仅剩下根分区与 /boot 分区的使用率,正好是我们所期望的。
注意选项“-X”与选项“-x”在命令中的顺序可以随意,没有前后之分。
测试成功后,修改NRPE配置文件“nrpe.cfg”,更新“command[check_df]”所在的文本行,其完整内容如下:
command[check_df]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10% -X tmpfs -x /dev |
重启NRPE服务,片刻观察Centreon Web管理后台,磁盘监控项目的输出缩短了,看起来更加清晰明了。