易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 4150|回复: 0
收起左侧

Nagios 监控 硬盘 I/O

[复制链接]
发表于 2017-12-13 17:51:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
下载完后直接上传到监控端和被监控端的的:/usr/local/nagios/libexec/ 目录.

' n) B& n+ b6 ?3 r/ g! [; ]
给它执行权限:

! `8 s# U0 ]4 N" F
chmod u+x check_iostat

3 |1 \! @+ l4 a
  [3 ]4 M- e7 W0 `
查看它的帮助:
- I! x6 b8 z: W4 ?. G8 G
[root@localhost libexec]# ./check_iostat -help
& F" j- ]* N. D/ p8 ^$ c9 v. q+ T
This plugin shows the I/O usage of the specified disk, using the iostat external program.
, {: F6 `$ i1 _! {! IIt prints three statistics: Transactions per second (tps), Kilobytes per second
+ u# u: Z2 H& y2 S! Y+ Vread from the disk (KB_read/s) and and written to the disk (KB_written/s)
  ~( Z! C! Z3 c# i& ?/ M4 U8 c* K# |! M! C3 G7 V
./check_iostat:
7 J$ U) |% `) p3 _-d Device to be checked (without the full path, eg. sda)
" w" n& V. n, m. O- s" f% J-c ,, Sets the CRITICAL level for tps, KB_read/s and KB_written/s, respectively
+ T' v$ ?/ Y% }5 f- \& T-w ,, Sets the WARNING level for tps, KB_read/s and KB_written/s, respectively" v, t" g; y( W9 R, Q, n
  U" c) _( }# z5 c- G

+ r9 V$ {4 y( l8 b( X
可以看到,它是用来检查硬盘上每秒数据写入读取的。
! e# B/ h' S( `: @$ G
参数分别是:
& s1 S: O. n; R8 Y
-d: 要检查的设备名称,不用写全路径

  }  c  z& A% _- d) p
-c: 当达到多少 KB/S 时就报 CRITICAL 级别的警
5 u- k! B6 M$ T) t4 v" J  D
-w: 当达到多少 KB/S 时就报 WARNING 级别的警
7 L$ \- m$ `9 s# i) ^
9 }0 V! j2 L2 z0 h5 A
查看本机的硬盘信息:

4 D' ^3 X- A+ s
[root@localhost libexec]# df -h; H, M: c2 d" n$ f1 P. r& t% D- N8 T
Filesystem            Size  Used Avail Use% Mounted on
: d1 r6 H) F% @  Z3 p/dev/mapper/VolGroup00-LogVol00
& A' \+ @3 x+ @/ [2 B+ w                      128G   27G   95G  22% /1 B, z8 y0 W3 T9 k5 x) q
/dev/sda1              99M   13M   82M  14% /boot! t9 M; P2 n* d9 o. l
tmpfs                 4.0G     0  4.0G   0% /dev/shm! o& u0 B: U. p

+ ~8 [! o5 I6 h5 x5 ^3 [# T' f
/ Y5 s- }6 f' ^5 a
上面的信息是 sda1, 那么 -d 后就写 sda

/ b! T1 ]2 R7 C. U
另外,还有可能不是 sda 的,如:

0 D) i4 w5 x* t" @
[root@li387-161 ~]# df -h
7 r+ Y' h1 ]' v! }Filesystem            Size  Used Avail Use% Mounted on
2 r; W3 n3 L4 a2 ?/dev/xvda              79G   38G   40G  49% /
& l  _7 B1 q. M" Q" m0 Dtmpfs                1009M  108K 1009M   1% /dev/shm! e4 F# B$ k! z" R& I6 f# u

9 n. g9 o1 M" {/ L
9 f; j9 x& K+ c/ C
上面的情况,-d 后就写 xvda

4 {9 E0 G& u  L4 \5 k& b; n' ]) t+ @, h6 W: e  V% N
检查是否能运行:

9 y$ I# k9 Y6 a5 \6 h" M
[root@localhost libexec]# ./check_iostat -d sda -w 1000 -c 2000( B( b* W) m3 @6 D/ v8 F
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;
+ V; {- {; t! x2 N5 L; X$ r. @- H; j

- c% Q' g$ e5 w7 m  R* Q  [
+ a3 R. ]& T7 t% L5 t
如果不能运行,报错,先在本机安装 sysstat:
' I% b+ r. b/ ^
[root@localhost libexec]# yum install -y sysstat

7 ~9 D% P/ C0 }0 P9 K) A2 O; T% F3 i" u
如果还报错,那就根据报错的信息一步步解决.

- E6 c6 V: q  H3 x$ s! O
比如我这边报过: bc: command not found ; 解决: yum install bc
4 n  z( s( P+ w# W
, ^3 J7 A/ N2 Y3 L4 Y
直到上面的 check_iostat 能正确执行.开始下一步配置.

, R* U# ?# W  t/ f0 ?. [3 i/ V2 C' [6 r- B* J
Nagios 配置
9 s/ T# R: a6 |9 X& h9 B
==========================

5 T0 t5 Y9 ^* {6 G& d4 b. l
监控本地:

" r+ s$ ^- J6 w7 ~% H9 l1 _$ B
------------

3 U3 h1 y/ u6 J
在 commands.cfg 中添加 check_iostat
. B- k. g2 m* A' A( [
define command{
, G! t5 n+ @. `! P) O3 P5 {& `        command_name    check_iostat5 f' i* U! d* u
        command_line    $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
5 k6 A  g9 K* U: @% w- {}
: W( X6 U7 N9 p& R6 K0 |

& t. e1 M; F) j
定义了 check_iostat 命令,且接收三个参数.

/ G* y) K  }8 l6 s$ {* p( x" x4 I: r
更改本地配置文件.假如叫: localhost.cfg
$ O: J* `/ P& K# s/ g, t
在里面定义一个服务:
6 ]3 d* v4 z$ w& u  b8 I
define service{
9 p0 Q$ s" E& V        use                             local-service         ; Name of service template to use# k( W- c4 b* W+ N
        host_name                       VOD-106
; b- Q- U7 r! W/ [( m2 S) g        service_description             Disk I/O
( ^% K% ?' b1 V/ P5 r' ~+ jcheck_period                    24x7 ; The service can be checked at any time of the day& n+ X& D5 i: O) ?2 o
        max_check_attempts              3 ; Re-check the service up to 3 times in order to determine its final (hard) state
; q5 u1 M6 j$ V- \% O, u4 Y+ c        normal_check_interval           2 ; Check the service every 10 minutes under normal conditions% y4 W7 v7 r; A/ ~
        retry_check_interval            1 ; Re-check the service every two minutes until a hard state can be determined( g0 `# j8 w4 x2 D7 z# M5 H, t
        contact_groups                  admins ; Notifications get sent out to everyone in the 'admins' group, L; F. {$ Z4 ^$ _/ t" }
notification_options w,u,c,r,f ; Send notifications about warning, unknown, critical, and recovery events
- I: B1 a9 P& Z! ~* [        notification_interval           1 ;
% X# [7 \/ N: A, g. u: D        notification_period             24x7 ; Notifications can be sent out at any time" T* X6 i7 ?+ U$ e% T9 F1 ~
check_command check_iostat!sda!1000!2000# _8 y# t. G; |( T$ G) v
}
8 \8 c: \0 R* \
) d& u2 O$ }+ m
如上红色部分所写.
. H; N6 c& u1 \/ E- x# k3 A# s
用感叹号分隔开参数.
5 o' q0 \6 N) R- u4 h! n
上面共有三个参数: sda, 1000, 2000 分别对应前面 commonds.cfg 中的三个参数.
6 x! u9 o; h& \9 _- Z5 s

, h3 v  H/ o/ r8 a( Q* [7 D; g) C
重新加载配置文件:

2 K( ^  L- }5 V4 M* ^
service nagios reload
% A4 D1 ?, S- h5 m  d4 v
  ~7 q- @% w2 w9 f& {
监控远程:9 Y2 {" c, a4 K; F4 Q1 d6 U% X
------------
, M! r7 b  J# _5 {0 O6 u

; [# b( S4 p2 l* {- Z. ^3 y& w
在监控端,修改远程服务器的配置文件.比如: remote.cfg

* [0 X3 @' I, V9 r! m5 N' X
: U$ m$ }, _1 h6 W
定义命令:
8 h) y2 U, K: A8 e" u1 |
define service{1 z/ r5 f# D  x# ?/ d
        use                             generic-service         ; Name of service template to use
/ s2 r! m, N: ]        host_name                       JP_VPS_2G$ S: n2 d: H6 o) r  ~
        service_description             Disk I/O  C- t5 U! J, z. C6 w! N) D. K
check_command check_nrpe!check_iostat
* Y1 @  p. l  _  L6 b$ O. e( I}- J! P2 x/ `) ~$ I2 Q4 k
0 V5 f- k& V, w
由于它是通过 check_nrpe 调用远程服务器上的命令.我们要在远程服务器上执行的命令就是这里 check_nrpe 命令的参数,即感叹号后的那个: check_iostat
! V- c. h6 U  m4 g
所以要确保被监控的机器上有 check_iostat 这个命令.安装方式和前面一样.
9 {9 U# x2 [, _9 F+ z
同时保证 check_nrpe 能顺利调用远程机器.可以通过命令尝试:
* Z7 P. ?' T  K
[root@localhost libexec]# ./check_nrpe -H 111.111.44.111
  l, m3 L: l5 H: rNRPE v2.13
- y4 ?" r0 F# t! ?3 i9 M) Y. E

1 ?% a9 L1 _5 M% ?8 T
0 i; W6 s! ^5 f0 m% z
然后更改被监控机器上的 /usr/local/nagios/etc/nrpe.cfg

  |' {: r9 |! p  C% P5 {- l
添加命令:

4 J1 J. _4 T/ U# P
command[check_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 1000 -c 2000
  W$ z6 |6 ^/ d" B5 L0 U
重启被监控端的服务:

2 D' z- `! ]- P% ^! b
service xinetd restart
% W6 R3 q& ~+ R% m1 Z$ Q) V# z' N

6 g+ D$ l  R2 ?

check_iostat

2.8 KB, 阅读权限: 10, 下载次数: 0

售价: 1 金钱  [记录]  [购买]

您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-8 23:51 , Processed in 0.165408 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表