|
下载完后直接上传到监控端和被监控端的的:/usr/local/nagios/libexec/ 目录.
6 }: c% u0 T$ n; ?5 l: J给它执行权限: " ]3 {+ C9 D2 ^/ z+ u* s
chmod u+x check_iostat g {) L% d2 ~) L
V1 d/ Z7 y% `# W2 L
查看它的帮助: 0 b* ?* D$ C4 i: i5 f
[root@localhost libexec]# ./check_iostat -help, M. `+ u' `, r% l
! E# d' v2 _& }
This plugin shows the I/O usage of the specified disk, using the iostat external program.. [, @9 X0 [7 p% d6 F
It prints three statistics: Transactions per second (tps), Kilobytes per second# ?/ v; B5 n- Y2 C- g; U
read from the disk (KB_read/s) and and written to the disk (KB_written/s)
( o9 e `& L7 D* K5 \# \; x5 r, e4 a0 ]) h& v0 a, m: W- h
./check_iostat:
0 V. I* {' Z5 b& o" e' k' J$ o-d Device to be checked (without the full path, eg. sda) y* L" T* v: k! O) `
-c ,, Sets the CRITICAL level for tps, KB_read/s and KB_written/s, respectively: K7 M- j. {) X2 T
-w ,, Sets the WARNING level for tps, KB_read/s and KB_written/s, respectively
' t% V" J" D' |7 d" f6 V
* Y- T5 m# i/ A
" s2 q# T' x. k }2 R* ?; B可以看到,它是用来检查硬盘上每秒数据写入读取的。
$ v. o9 y: k* E8 R0 S参数分别是:
' [) V/ n+ }; z: x" N" j-d: 要检查的设备名称,不用写全路径 4 ]$ w1 r( F# k# i, U' c) o
-c: 当达到多少 KB/S 时就报 CRITICAL 级别的警
" ~" Q$ Z; { H* c8 \# w-w: 当达到多少 KB/S 时就报 WARNING 级别的警 % E8 i2 B2 v- p4 Z' E6 E
y+ q: A$ K* l: r1 s查看本机的硬盘信息:
! Z" w( z, D; t ]( o[root@localhost libexec]# df -h
`' W& C* `( q( s/ H) aFilesystem Size Used Avail Use% Mounted on" G5 M3 e, [) B4 [9 S* u# a5 O X
/dev/mapper/VolGroup00-LogVol00
; i- E, D0 ]! r- |0 i/ j1 M 128G 27G 95G 22% /
/ U+ O5 I9 G' b) u5 t/dev/sda1 99M 13M 82M 14% /boot
8 B, {0 O! S7 P+ `* X$ y3 _4 M9 Ktmpfs 4.0G 0 4.0G 0% /dev/shm
B$ K; [+ p8 w% v
$ A. |! m" O& z a* ~" c3 o7 d- W! R- b7 \' A! _
上面的信息是 sda1, 那么 -d 后就写 sda
* T' O U4 I3 s% F1 ?$ r另外,还有可能不是 sda 的,如: p; b f! `9 s
[root@li387-161 ~]# df -h
6 f6 a4 o; j8 U5 ]( F* fFilesystem Size Used Avail Use% Mounted on
) _' J% m' {, [, D, L' y4 w2 Y/dev/xvda 79G 38G 40G 49% /0 U: [) ?0 o$ `/ O7 H) Q* c7 S
tmpfs 1009M 108K 1009M 1% /dev/shm3 \, {$ _* k' q. _9 {) T- Z
1 y3 ?1 o& L! b+ C
: R0 u9 N/ `, o' w( v上面的情况,-d 后就写 xvda - B3 p) B7 s0 y( D9 f2 H% N
% t# U5 ?; J" w4 l+ y
检查是否能运行:
3 D. R( j$ ]3 V" o5 }: n[root@localhost libexec]# ./check_iostat -d sda -w 1000 -c 2000
/ m. }$ Q4 m1 m7 t- d1 L5 `( JOK - 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;( o4 B. `: {* x' b2 C7 h: @4 w
: y- T7 V% t0 _; }& X4 A3 P. x$ O* l( d2 q
如果不能运行,报错,先在本机安装 sysstat:
$ K( V( M Q5 ]& Y/ [' G[root@localhost libexec]# yum install -y sysstat , B/ L0 ~1 |( k0 [$ v! f9 Z, R
如果还报错,那就根据报错的信息一步步解决. ! V6 ?1 {" g0 }6 T& i3 ^6 I
比如我这边报过: bc: command not found ; 解决: yum install bc / M X* E/ E$ K- [, D
: @# L' I5 U. e" Q直到上面的 check_iostat 能正确执行.开始下一步配置.
7 Q' @, i/ U+ j6 e# L! d0 W6 W8 F! Z7 T2 j
Nagios 配置
- q0 Q+ q$ ~- w' O p; H O% Q$ y========================== `: U8 U4 M; M4 C7 Q
监控本地: ! F9 u, w1 f1 F8 F/ u0 v
------------ . a. j( N$ p7 \( W0 g
在 commands.cfg 中添加 check_iostat
0 j6 D2 w" a0 o) u$ O: V$ i Odefine command{
) E# j0 w. V7 E k" s6 | command_name check_iostat
' m/ L, w# a) z* J$ W: R- {. } command_line $USER1$/check_iostat -d $ARG1$ -w $ARG2$ -c $ARG3$* `& O* h9 f* _/ V; B
}
+ k. x$ M: m* Y( E: m" l
. y' k* N% C5 ?: J/ ~; S1 r7 x% ^定义了 check_iostat 命令,且接收三个参数. 6 I$ Y+ j3 R& J
* H# C' |2 I1 p0 T# q# U6 @/ N
更改本地配置文件.假如叫: localhost.cfg 4 B5 |9 I7 I/ H& ` \
在里面定义一个服务:
3 T2 t- f. F C3 H$ J! \1 `" Xdefine service{
9 w$ _5 P2 g* e) g* [ use local-service ; Name of service template to use
2 i" m/ R7 x' z/ D' z) s4 G host_name VOD-106% j/ a9 A9 F# o/ I- M
service_description Disk I/O
6 S1 l) |) A& F1 j0 Z9 \ c9 lcheck_period 24x7 ; The service can be checked at any time of the day
9 r5 N: _% X3 _" B& E max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
. w8 m- u! P" S/ ?3 B normal_check_interval 2 ; Check the service every 10 minutes under normal conditions5 V6 R* l3 h6 X
retry_check_interval 1 ; Re-check the service every two minutes until a hard state can be determined
/ L$ k: P4 ^( N; N contact_groups admins ; Notifications get sent out to everyone in the 'admins' group/ Y& K- D& k, R6 N. _5 P# i
notification_options w,u,c,r,f ; Send notifications about warning, unknown, critical, and recovery events3 g' S% f5 F4 Q) {0 U
notification_interval 1 ;
: Y) T0 u1 O! @! B; @6 ^ notification_period 24x7 ; Notifications can be sent out at any time
' k1 R# R+ i, b( u- Icheck_command check_iostat!sda!1000!2000
8 j6 ^3 M3 b% I% l6 J0 [! B}
1 @) H+ |2 e, K9 V+ [4 S
! I" Q! L& @9 B0 S6 A" ^如上红色部分所写.
- h$ ?5 m' u) u; h$ U8 \3 z用感叹号分隔开参数. : o4 }) ~$ U! O! N. i m, @
上面共有三个参数: sda, 1000, 2000 分别对应前面 commonds.cfg 中的三个参数. 7 w B: [8 h$ e+ o% s; `/ ]4 `
. J3 ]7 v3 l, b9 ?4 X
重新加载配置文件:
2 F- n1 \3 O( a1 {! O% B' p! xservice nagios reload 9 m/ @; t( w6 r/ Q6 R) v1 E% n' }
/ s9 O b' t9 I8 a4 J% t6 N
监控远程:/ _" D8 t- h. h- U2 |
------------4 |! ?! g9 e- m6 S# B; l
' _- a- T2 p! T4 Q
在监控端,修改远程服务器的配置文件.比如: remote.cfg
& y9 A& I% Y5 l" }1 m# ^! ]( _% A Q K n
定义命令:
* E3 {+ M M8 q) N; Sdefine service{
" v& I. t* E6 R/ L use generic-service ; Name of service template to use
" b, G( I$ t. ~; e% V host_name JP_VPS_2G
3 A5 g. y0 H& V, q' n* I service_description Disk I/O1 I8 V! D' _# y+ W6 G
check_command check_nrpe!check_iostat
8 _$ j7 J& |& n# k: l}
9 U4 J8 B8 f1 h1 l, T! }) _
9 {0 d9 y( v7 J0 f( D由于它是通过 check_nrpe 调用远程服务器上的命令.我们要在远程服务器上执行的命令就是这里 check_nrpe 命令的参数,即感叹号后的那个: check_iostat : P' j: f6 F$ f) _& l7 K1 L& S/ x
所以要确保被监控的机器上有 check_iostat 这个命令.安装方式和前面一样. 6 w& g. |7 O! X- y8 l+ |
同时保证 check_nrpe 能顺利调用远程机器.可以通过命令尝试: $ ^- v& X Y1 Z. V/ I) ~/ O0 y0 H
[root@localhost libexec]# ./check_nrpe -H 111.111.44.111
0 m, A6 b1 a, b, XNRPE v2.13
5 W2 P( C4 b8 H ; U- F: N* C0 Q! M
0 C0 o* K2 V) N) Y+ H# o% q
然后更改被监控机器上的 /usr/local/nagios/etc/nrpe.cfg
6 A; u c, a* d1 s添加命令:
, ^3 M3 i+ T; u1 ~* N, _( G7 Ncommand[check_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 1000 -c 2000 % r0 @, W3 b* i+ C. f6 L+ S' z8 \ l
重启被监控端的服务:
+ e; P8 s% s* W, F4 K8 Mservice xinetd restart : l4 o2 Z& i- b! P7 z% D5 X% U
. L! e3 b4 ~' w' O& M |