马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?开始注册
x
下载完后直接上传到监控端和被监控端的的:/usr/local/nagios/libexec/ 目录.
5 }" d- Z$ Z& H+ m给它执行权限: 9 b9 |5 d# G- H
chmod u+x check_iostat
: {, g8 O7 z8 w0 n, n" J
9 e, f) H4 L9 g! n# t; R- [查看它的帮助:
( s$ l/ h" u- n! b) l% T9 u[root@localhost libexec]# ./check_iostat -help
# R- j1 Q+ {$ w- I# ?# w( [% g! O1 R# x3 } l! N
This plugin shows the I/O usage of the specified disk, using the iostat external program.0 @1 q$ f& ~9 w+ N
It prints three statistics: Transactions per second (tps), Kilobytes per second* m% b( \! ^' r; p/ }
read from the disk (KB_read/s) and and written to the disk (KB_written/s)
5 x, p$ Y$ W! }' ~5 a$ \3 V) d3 c2 e$ U4 n. _: v( ^
./check_iostat:
( ~' j z. w/ e* l1 ?-d Device to be checked (without the full path, eg. sda)
- f& V+ w9 j' u* Q0 F8 J+ s-c ,, Sets the CRITICAL level for tps, KB_read/s and KB_written/s, respectively
" e5 t6 c* u. s! C2 i-w ,, Sets the WARNING level for tps, KB_read/s and KB_written/s, respectively
1 L. @/ a9 T. j4 V; k 7 p5 ]2 r) i' A
! K6 D, {' T2 x" S可以看到,它是用来检查硬盘上每秒数据写入读取的。
|$ c7 A3 Q! k2 @" B参数分别是: 5 s E& o7 S+ F/ o! s5 w; O1 s3 C
-d: 要检查的设备名称,不用写全路径
+ t* g9 r& ]1 u9 |+ h- V, F-c: 当达到多少 KB/S 时就报 CRITICAL 级别的警 ; c8 h, e* E" j
-w: 当达到多少 KB/S 时就报 WARNING 级别的警 4 j$ q" X, q1 b7 f. [
; ~- K5 O1 |7 e% d7 ^查看本机的硬盘信息:
4 t; X: {2 }$ h' R+ S[root@localhost libexec]# df -h. c; m/ e! g# c) R$ m+ T" O
Filesystem Size Used Avail Use% Mounted on
) ~4 K; X4 D+ _. e2 \9 v$ _/dev/mapper/VolGroup00-LogVol00
. _) X* V. k$ }5 P 128G 27G 95G 22% /! h2 I! i! d$ O3 a d
/dev/sda1 99M 13M 82M 14% /boot' x f+ w L0 s I7 X
tmpfs 4.0G 0 4.0G 0% /dev/shm
$ b: w$ w& I8 ^2 F! Z: V' X
4 v: f- t6 A* [$ C: z! u2 H% A1 ]. b/ z! f- f
上面的信息是 sda1, 那么 -d 后就写 sda
1 N% c }6 c; \0 @2 e$ l4 F另外,还有可能不是 sda 的,如: - F( v2 N) d% `) ?* Y
[root@li387-161 ~]# df -h
J/ w* R/ M2 P" @! u: r3 [Filesystem Size Used Avail Use% Mounted on
# I9 s( x% z% r1 [' Y. `4 K% b/ E/dev/xvda 79G 38G 40G 49% /
% P; L: `9 I" Ztmpfs 1009M 108K 1009M 1% /dev/shm( ^" q T6 W% P8 e. F' ?+ c
+ b6 X W. p/ R. i$ X# d
/ P/ w! R$ _' j7 }8 y+ [上面的情况,-d 后就写 xvda + M! _+ c- I. S! `
$ T0 I# L" ?* l
检查是否能运行: . t/ u+ }( s: l5 Y- c, V
[root@localhost libexec]# ./check_iostat -d sda -w 1000 -c 2000
5 i* H1 I' s" G, qOK - 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;; R5 a3 s2 f2 g) x; `( v
5 j# |6 ~2 `8 k5 ~' V5 p. ^4 v* f) R0 H4 x0 k
如果不能运行,报错,先在本机安装 sysstat:
) Q/ @' a* _6 n: \" d: v/ S7 v[root@localhost libexec]# yum install -y sysstat ! p9 |+ w& ^9 r# ]9 |& Y5 f( O* z
如果还报错,那就根据报错的信息一步步解决.
; q; @. W& t9 f/ p$ @比如我这边报过: bc: command not found ; 解决: yum install bc
9 O/ Z( I/ l( ^; o' ]3 R
! ? B0 }: r8 p0 b* z0 Q# {" P5 ]直到上面的 check_iostat 能正确执行.开始下一步配置.
5 ]: y+ U2 R$ T6 E; V( o. A f
/ ?9 N5 i/ K' m% W* T# ~9 s) s, `0 h9 bNagios 配置 4 B4 v$ z4 @( T4 c e0 G$ p; n% z
========================== W. d" X4 ^! {7 A" M( S
监控本地:
+ k7 m+ h0 I; T2 h8 h* I------------ 9 x4 G4 N! a* B/ Q& g$ E3 M9 X
在 commands.cfg 中添加 check_iostat
4 t8 |) N4 h5 t! s0 J: qdefine command{; d9 x. ~) ]! V7 R# g
command_name check_iostat
9 N7 m4 ?. @" b3 ] command_line $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
8 P5 a, C6 b/ T}, K: P. |0 @" P' h% |2 s/ D
. g) Z9 ~; c; H! F9 s: H定义了 check_iostat 命令,且接收三个参数.
, P2 F" y* t: d$ J/ X
b9 I, L! U! Q# a6 g更改本地配置文件.假如叫: localhost.cfg 2 V+ J0 b* c& V" a9 u
在里面定义一个服务:
" N0 j$ h$ N1 Y/ s: W7 G$ {define service{" E# u' p% Z) T p; }5 o5 z
use local-service ; Name of service template to use
7 F' I; ^8 c5 z7 V- c# j" V) U host_name VOD-106/ R: H! G' r9 i# m) B& B$ z( L. z
service_description Disk I/O
( E E( T' t+ _$ W# F/ J, R3 g7 Y! Lcheck_period 24x7 ; The service can be checked at any time of the day
3 u. G: w8 f0 L- y; w) {! H+ [# K; i max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state, I, ^1 Q3 k: B# o: E+ g" o1 c. o! k
normal_check_interval 2 ; Check the service every 10 minutes under normal conditions
! V/ ~" {' j$ Q" C retry_check_interval 1 ; Re-check the service every two minutes until a hard state can be determined7 l+ w( R% [# {1 d- Q! M' Q/ T
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group
; y6 S, u$ k! I: h7 ^. jnotification_options w,u,c,r,f ; Send notifications about warning, unknown, critical, and recovery events
6 ~2 j# A/ k X, l notification_interval 1 ;
* o' ~1 c d/ [) [0 U9 ~6 }1 K notification_period 24x7 ; Notifications can be sent out at any time
) `1 v w% k, I! G, T2 echeck_command check_iostat!sda!1000!2000' U' g* `: G0 w, y4 x6 Y
}4 w2 }8 L! k' O5 ?
& Z- y9 m% c; L6 s( s* V% @' V如上红色部分所写.
3 P" K; h8 r7 A# D用感叹号分隔开参数.
+ i- A/ b B7 y9 Y5 B8 F" [8 v上面共有三个参数: sda, 1000, 2000 分别对应前面 commonds.cfg 中的三个参数.
4 ]- O& S0 n* D0 \. m* k( I' E* W
* L% K0 r- c0 ]0 |重新加载配置文件: 3 e/ f; o0 G) n. R5 e
service nagios reload
0 A+ l& B1 A' Z/ d6 q; X, U" p) V$ {1 ]% Q' r( i% `6 J
监控远程:
% u% B# A- Z7 @% Q) E' u5 G; V------------" Y+ s1 `1 A3 I" x1 u+ k
' K7 [" @5 W4 h$ M) G: i
在监控端,修改远程服务器的配置文件.比如: remote.cfg & N2 N1 t H2 o0 k S* I
0 ]6 n+ q w- a: p
定义命令: ( J. o6 R8 T+ Q+ P0 m8 n# }* \- N
define service{; H5 s! Z2 {% B. F
use generic-service ; Name of service template to use
: f8 X5 }- k( j) ~3 y4 d host_name JP_VPS_2G
* E+ Z9 v7 D* r) z+ e; O. [- ~ service_description Disk I/O
' y1 J- d1 R( i0 S# Ycheck_command check_nrpe!check_iostat1 o* H: \6 ?& U4 {) ?
}
* b6 j6 a0 w4 c( _! z # ?" o, }$ ^( T9 b) y# l
由于它是通过 check_nrpe 调用远程服务器上的命令.我们要在远程服务器上执行的命令就是这里 check_nrpe 命令的参数,即感叹号后的那个: check_iostat 9 k0 s* k, `( ]3 ?0 ~
所以要确保被监控的机器上有 check_iostat 这个命令.安装方式和前面一样.
+ l4 S8 Y" U/ f8 v" ~. |4 [同时保证 check_nrpe 能顺利调用远程机器.可以通过命令尝试: * @! K! h5 ^5 b3 D) x' x, n
[root@localhost libexec]# ./check_nrpe -H 111.111.44.111; [; H% }1 q$ i1 S: _# F U
NRPE v2.13" N" a- N3 \/ I8 H
; q, r" `2 n& d' ~* z7 W! N p
- s5 h6 e# W$ G: O4 |1 r6 K) h然后更改被监控机器上的 /usr/local/nagios/etc/nrpe.cfg
. L' i2 J3 r. [- f添加命令: . ?6 O; t5 } M b/ y# e
command[check_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 1000 -c 2000
, W- c6 k, }! h S重启被监控端的服务:
8 F3 \' t1 A& I* [service xinetd restart
$ _* U1 v1 K! o$ A6 u1 P% A
# x' E$ `1 D6 C9 I( u& J0 L; N |