|
下载完后直接上传到监控端和被监控端的的:/usr/local/nagios/libexec/ 目录.
Y& Q; G# j3 Q$ B- H给它执行权限:
+ K; ~6 _; j$ j3 V5 _* cchmod u+x check_iostat
: M9 D/ b1 R" x* Z% v3 @! L$ o* U: j6 t+ _3 a$ s& J9 l& ^
查看它的帮助: / K! |0 H, P8 r3 p9 O- e/ @9 I
[root@localhost libexec]# ./check_iostat -help! F9 R& V. `2 v
- u. H0 D6 J- V- o' D0 f O/ @/ k) {
This plugin shows the I/O usage of the specified disk, using the iostat external program.
4 V( H8 p5 B" YIt prints three statistics: Transactions per second (tps), Kilobytes per second% o; F! {7 ]4 c! }) R, t: a+ T- U
read from the disk (KB_read/s) and and written to the disk (KB_written/s)
5 \, T; M8 w$ l; t8 \
! d; k. Z& | a5 R5 W./check_iostat:7 p: \- Z0 ~& v+ V
-d Device to be checked (without the full path, eg. sda)4 G' o/ q1 x9 O+ M. o
-c ,, Sets the CRITICAL level for tps, KB_read/s and KB_written/s, respectively
7 _7 G4 w' Z: S ?-w ,, Sets the WARNING level for tps, KB_read/s and KB_written/s, respectively
+ y3 E( y* {- @, P9 V& H
6 D5 F- q7 q: d% Q C) k
- g6 v4 |! p# a- w; _# q" o! F可以看到,它是用来检查硬盘上每秒数据写入读取的。
8 b d( @! I! s参数分别是: % |7 g$ B/ S4 K+ X
-d: 要检查的设备名称,不用写全路径
' t. r( f N* V) a6 J6 W& s-c: 当达到多少 KB/S 时就报 CRITICAL 级别的警
% i! q+ P4 W1 T3 J. N8 ?-w: 当达到多少 KB/S 时就报 WARNING 级别的警 O8 B* O: ], u3 B6 g. t6 O4 l
: k$ f; O! n) X* p: P0 ^# x
查看本机的硬盘信息:
W$ G' B- ~2 b5 R[root@localhost libexec]# df -h
2 \/ M2 c/ y9 F. qFilesystem Size Used Avail Use% Mounted on, Q+ |, O+ g) U* S
/dev/mapper/VolGroup00-LogVol00
5 H% ?5 l, n, x4 {% X+ c4 _ 128G 27G 95G 22% /
" ?9 |4 J- h O3 V% e/dev/sda1 99M 13M 82M 14% /boot L. X: x( g2 @+ X/ T2 L, s
tmpfs 4.0G 0 4.0G 0% /dev/shm& Q1 s' a/ n' y' ~
3 B4 W2 N; x. o+ t3 g0 \; n6 L; o- g& k
上面的信息是 sda1, 那么 -d 后就写 sda 1 t0 v% E( a; d ~$ Y( K$ V z$ z6 |. K
另外,还有可能不是 sda 的,如: ( t/ }3 O. U1 p& |( M3 W! S- [6 ^
[root@li387-161 ~]# df -h
: C6 }/ F2 k# b6 K/ M! z" {7 pFilesystem Size Used Avail Use% Mounted on& v6 T' r/ i2 _; N9 N( v' `
/dev/xvda 79G 38G 40G 49% /! @: t* K9 i1 f" Q9 i
tmpfs 1009M 108K 1009M 1% /dev/shm
: S- y8 D) h! c. t5 }$ x Z2 ` L! @! t5 x) A" w
* X- m- r: s3 S+ q# h上面的情况,-d 后就写 xvda
& W3 O% q3 U3 D% n$ N8 c+ w; Y& {& I1 H0 [$ x6 i. l
检查是否能运行: 4 v( p5 _1 B# |9 v
[root@localhost libexec]# ./check_iostat -d sda -w 1000 -c 2000
- T% J) P* K3 h: L# D; FOK - 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;) h6 Q2 B* c8 @0 c; W
: [/ S1 h* a* I4 A# I1 _2 U6 p
, v, E Y, c6 W& p( I5 w如果不能运行,报错,先在本机安装 sysstat:
! b T" C( \ |8 L7 f; Y; P6 ~[root@localhost libexec]# yum install -y sysstat
3 y, r6 D) Y! t1 m+ r! i+ G如果还报错,那就根据报错的信息一步步解决. . o9 [2 x2 M) d P
比如我这边报过: bc: command not found ; 解决: yum install bc * O* r2 |; Y$ n2 N+ F
) W. d7 r5 l) K! E直到上面的 check_iostat 能正确执行.开始下一步配置. 0 [. z+ ?: ~) x
5 t- B( L5 t8 L7 U6 m" F1 r/ RNagios 配置
; n! j, v- y* {" Z0 `. M========================== - f1 }( `, i u+ L5 b
监控本地:
0 B1 ]; e, n5 t( m5 v; ~) Z5 I------------ 1 i) I$ k9 t' J2 h% u
在 commands.cfg 中添加 check_iostat
, l% `- z% k- |; f/ k0 }define command{ |# [2 a9 ?$ o5 d) W! y! F
command_name check_iostat0 J3 Z: v, ?; K* `8 t
command_line $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$
$ c l2 \8 B1 E% F* x0 _}
( q1 f% f: Z+ O7 x) D' T. W2 I: |# N
% `( [6 A/ U- V* q3 ]7 f定义了 check_iostat 命令,且接收三个参数.
8 a( M) I8 i6 L
+ i5 N: K6 ], |7 ]2 X" F1 t4 c+ O# ~更改本地配置文件.假如叫: localhost.cfg
/ V! I( j+ f# q) W1 }5 r在里面定义一个服务: 6 ~6 Q1 y5 F& B
define service{8 J* v0 u! ]$ ?4 K* H F) Y: {
use local-service ; Name of service template to use) \( i M" c9 F( P$ _$ P" ~0 {. L
host_name VOD-106( E; ^# G+ N% p$ n& |- T0 |* f. K
service_description Disk I/O% N: r. ^, d8 U% Y3 E5 X
check_period 24x7 ; The service can be checked at any time of the day7 ]$ V. v& |0 }' o' L( j' p5 g" |
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state4 m! \& A* y& c# y7 ?
normal_check_interval 2 ; Check the service every 10 minutes under normal conditions
% ^6 X% o: ~* F" `2 ?: Y retry_check_interval 1 ; Re-check the service every two minutes until a hard state can be determined
1 C, Z$ l! J6 E* Q: j+ a4 X& i contact_groups admins ; Notifications get sent out to everyone in the 'admins' group- S5 v4 K8 q7 z& f: Q$ |. g
notification_options w,u,c,r,f ; Send notifications about warning, unknown, critical, and recovery events/ M; ]) t* |; a0 _4 P2 ?4 Z" |
notification_interval 1 ;
: k$ r- W8 [. J; H notification_period 24x7 ; Notifications can be sent out at any time
" h8 |5 H' r5 S5 E' H5 @check_command check_iostat!sda!1000!2000
! B Z1 F, ?3 Z6 N3 N% s4 v+ A- q6 Q}6 x B( u" C) }$ b
" q+ L4 x l! b3 P/ H+ K5 g如上红色部分所写. + `8 h* q+ a5 I. U, M
用感叹号分隔开参数. - E& q* Q! t8 N/ g
上面共有三个参数: sda, 1000, 2000 分别对应前面 commonds.cfg 中的三个参数.
y; K8 G4 \* x" g
$ [& c: M9 w5 B( k. u重新加载配置文件:
; | D e# |9 K5 K6 R6 w8 Sservice nagios reload
+ w# b4 m( C3 Q; d2 P* O5 S1 N. q+ Q3 Q; c) Y* [0 C3 ]
监控远程:
# X. {, t* m7 j. A) P$ }3 a' E2 X M------------ s3 s" J& M6 @
6 C' E( @9 t' N在监控端,修改远程服务器的配置文件.比如: remote.cfg
. a, ]) h5 [8 G, o9 K/ u
, U0 p( a" g- `2 ~5 @定义命令:
* [$ f6 k2 l5 s3 j2 m) `+ \define service{& I9 L' h7 R6 L6 [
use generic-service ; Name of service template to use% Q k" E8 C9 y9 @7 Y, H0 D- x+ v
host_name JP_VPS_2G: s+ j) r. y8 ?8 Y) @
service_description Disk I/O4 `0 D( l2 Q/ C/ o2 s/ G7 A7 Z
check_command check_nrpe!check_iostat# r) l$ N( Q1 d: r/ {
}2 W& N0 w: e& p$ b, n# }# ?
' ^: L+ z4 ?" [4 E$ S/ p9 \
由于它是通过 check_nrpe 调用远程服务器上的命令.我们要在远程服务器上执行的命令就是这里 check_nrpe 命令的参数,即感叹号后的那个: check_iostat . E2 g1 U, g8 E4 u# {
所以要确保被监控的机器上有 check_iostat 这个命令.安装方式和前面一样. 3 i* n. Q+ {( X: ]/ r
同时保证 check_nrpe 能顺利调用远程机器.可以通过命令尝试:
; W- j+ K% f- e) Y- u6 Y[root@localhost libexec]# ./check_nrpe -H 111.111.44.111' N5 U; p' a, N3 q) t/ z1 R: \+ ]4 h
NRPE v2.13
8 \* l: n8 B( @% B# n; [6 ^
7 m1 W$ f8 E5 a+ i' o6 u9 k7 }
7 O( j8 y# w# }+ o; \; \6 v7 ~然后更改被监控机器上的 /usr/local/nagios/etc/nrpe.cfg
0 J, W9 U+ Q B- ?添加命令:
3 G, V5 b6 C" U5 v5 R- M( L6 n" w5 ccommand[check_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 1000 -c 2000 # o; M5 S k5 A. \0 J
重启被监控端的服务:
5 A9 J* V1 n) A' C% Wservice xinetd restart
5 n( F! Z, X+ H' ], w" i' y2 F; b5 C
|