Linux - Nagios 监控 硬盘 I/O 端口

上一篇《Linux下Nagios的安装与配置 及遇到的坑

Nagios 自带的包里没有直接检查硬盘 I/O 的包: check_iostat,不过可以到官网上下载一个,下载页面是:

http://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_iostat--2D-I-2FO-statistics/details

下载完后直接上传到监控端和被监控端的的:/usr/local/nagios/libexec/ 目录。
给它执行权限:

chmod +x check_iostat

查看它的帮助:

[root@localhost libexec]# ./check_iostat -help
This plugin shows the I/O usage of the specified disk, using the iostat external program.
It prints three statistics: Transactions per second (tps), Kilobytes per second
read from the disk (KB_read/s) and and written to the disk (KB_written/s)
./check_iostat:
-d Device to be checked (without the full path, eg. sda)
-c ,, Sets the CRITICAL level for tps, KB_read/s and KB_written/s, respectively
-w ,, Sets the WARNING level for tps, KB_read/s and KB_written/s, respectively

可以看到,它是用来检查硬盘上每秒数据写入读取的。
参数分别是:

  • -d: 要检查的设备名称,不用写全路径
  • -c: 当达到多少 KB/S 时就报 CRITICAL 级别的警
  • -w: 当达到多少 KB/S 时就报 WARNING 级别的警
    查看本机的硬盘信息:
[root@localhost libexec]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      128G   27G   95G  22% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm

上面的信息是 sda1, 那么 -d 后就写 sda
另外,还有可能不是 sda 的,如:

[root@li387-161 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda              79G   38G   40G  49% /
tmpfs                1009M  108K 1009M   1% /dev/shm

上面的情况,-d 后就写 xvda
检查是否能运行:

[root@localhost libexec]# ./check_iostat -d sda -w 1000 -c 2000
//输出 OK - I/O stats tps=1.71 KB_read/s=2.77 KB_written/s=26.77 | 'tps'=1.71; 'KB_read/s'=2.77; 'KB_written/s'=26.77;

如果不能运行,报错,先在本机安装 sysstat:

[root@localhost libexec]# yum install sysstat

如果还报错,那就根据报错的信息一步步解决.
比如我这边报过: bc: command not found ;
解决:

yum install bc

直到上面的 check_iostat 能正确执行,继续配置

Nagios 配置


监控本地
在 commands.cfg 中添加 check_iostat

define command{
        command_name    check_iostat
        command_line    $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
}

定义了 check_iostat 命令,且接收三个参数.
更改本地配置文件.假如叫: localhost.cfg
在里面定义一个服务:

define service{
        use                             local-service         ; Name of service template to use
        host_name                       VOD-106       ;服务器名
        service_description             Disk I/O      ; 描述,尽可能不要用中文
check_period                    24x7 ; The service can be checked at any time of the day
        max_check_attempts              3 ; Re-check the service up to 3 times in order to determine its final (hard) state
        normal_check_interval           2 ; Check the service every 10 minutes under normal conditions
        retry_check_interval            1 ; Re-check the service every two minutes until a hard state can be determined
        contact_groups                  admins ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r,f ; Send notifications about warning, unknown, critical, and recovery events
        notification_interval           1 ; 
        notification_period             24x7 ; Notifications can be sent out at any time
check_command check_iostat!sda!1000!2000
}
check_iostat!sda!1000!2000
// 上面共有三个参数: sda, 1000, 2000 分别对应前面 commonds.cfg 中的三个参数.

重新加载配置文件:

service nagios reload

监控远程:

在监控端,修改远程服务器的配置文件.比如: hosts.cfg 文件对应主机的 services.cfg 文件内修改(例如在hosts.cfg,对应3台主机,其中一台名:test.local,那就需要在services.cfg中增加配置如下)
定义命令:

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       test.local      ; 主机名
        service_description             Disk I/O
check_command check_nrpe!check_iostat
}

由于它是通过 check_nrpe 调用远程服务器上的命令.我们要在远程服务器上执行的命令就是这里 check_nrpe 命令的参数,即感叹号后的那个: check_iostat
所以要确保被监控的机器上有 check_iostat 这个命令.安装方式和前面一样.
同时保证 check_nrpe 能顺利调用远程机器.可以通过命令尝试:

[root@localhost libexec]# ./check_nrpe -H 111.111.44.111
NRPE v2.13

然后更改被监控机器上的 /usr/local/nagios/etc/nrpe.cfg
添加命令:

command[check_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 1000 -c 2000

重启被监控端的服务:

service xinetd restart

至此从监控主机上可以看到远程/本地磁盘读写信息

磁盘读写信息

监控指定端口
修改被监控主机 /usr/local/nagios/etc/objects/commands.cfg 添加一个服务名

# check port 4000
define command{
        command_name    Port_80 ; 命令名,后期在监控主机中需要用到
        command_line    $USER1$/check_tcp -H $HOSTADDRESS$ -p 4000 $ARG2$
        }

在监控主机中 services.cfg 中增加监控服务

# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
        use                             local-service         ; Name of service template to use
        host_name                     test.local  ; 监控的主机名,需要和hosts.cfg对应
        service_description            80 ; 描述
        check_command                  Port_80 ; 命令,被监控主机定义的
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              2
        normal_check_interval           1
        retry_check_interval            1
        contact_groups                  admins
        notification_options            w,u,c,r
        notification_interval           960
        notification_period             24x7
        }

重启nagios

# service nagios restart

刷新页面如下

监听80端口
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,233评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,013评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,030评论 0 241
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,827评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,221评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,542评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,814评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,513评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,225评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,497评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,998评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,342评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,986评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,812评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,560评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,461评论 2 266

推荐阅读更多精彩内容