|
|
之前用过一款监控网络流量的插件,感觉不太好用。因为他的in和out值只能限制到一个值。下面新用一个插件in和out值能够分别定义。和以前的插件方法大概相同。2 B8 J& B/ P7 H6 ]- x
- Q% d( r4 |% X$ K1. nagios主机安装net-snmp和RRDTOOL# |& G- P4 g9 Q( V4 a
2. 参照cacti,windows和linux的监控。在被监控主机上添加nagios主机IP% k$ b/ k) m9 w
' n! K6 q2 U6 j- {! \
1. 查找以下字段
/ c! S& s* h% v! ~! d; r# sec.name source community
3 _' y* n# v( h+ s, q) }9 Ccom2sec local 127.0.0.1 public
! w3 n! g$ [+ M2 U/ q8 Ycom2sec local 192.168.2.2 public: u& G9 r" Y; r0 `4 R4 {, V* h
#将"comunity"字段改为你要设置的密码.比如"public".将“default”改为你想哪台机器可以看到你的snmp信息,如192.168.2.2,我这里将source修改成了nagios主机。; M H: D- K, U# x
2. 查找以下字段
+ n# U7 O& S. F6 O. |# context sec.model sec.level match read write notif
5 p/ m1 B7 _& |( P6 naccess MyROGroup "" any noauth exact all none none' E7 D# O w' y% T9 s: Q6 t
access MyRWGroup "" any noauth exact all all none
+ K9 u* b2 v8 G2 K9 y, f0 _#将read字段修改成all
/ [ R: T+ Q z( Z+ \3. 查找以下字段
k: ^* ~" C ]3 F" V8 S# incl/excl subtree mask5 s+ W3 n5 s& F; T8 j' B! H
view all included .1 80
8 q. ^0 u2 O7 O4 k* q- o* f#把view前的#去掉1 P( P S2 T$ L3 J3 E; g& f( a. n3 D
]9 F; T. P3 t" C' E1 z i3. 测试1 D6 S* S, R0 A" y6 o- B
重启 snmp, z- z4 j9 D& F0 [, C1 y6 _
service snmpd restart# r8 R8 [2 L$ \: u2 p6 M* E
在被空端:( S+ l2 M* ?3 Q
snmpwalk –c public –v 2c localhost
' x+ a [+ h1 {* W7 F# J在主控端测试
; f4 D5 y1 ~8 h$ ~3 R/ z4 ksnmpwalk -v 2c -c public 被控端ip |grep IF% K5 P" p5 C; ^8 G8 s
如果没有if信息不能获取流量/ z. L% z4 S: x. h6 O3 Q
3. 获取被控端网卡信息
. w; X( Y6 u" H
' Y& V4 u/ T0 j- K* q[root@localhost libexec]# ./check_traffic.sh -V 2c -C public -H 192.168.2.6 -L
' @: Q- f& s; E- j; zList Interface for host 192.168.2.6.
4 ]# Z7 i# L/ uInterface index 1 orresponding to lo. l/ A/ E# t3 u. c' Y
Interface index 2 orresponding to eth0# b) B- O- ?4 K m, R
Interface index 3 orresponding to eth1$ r& s+ g1 i2 z Q7 J
: C0 L8 J: _1 T4. 在nagios主机上添加check_traffic脚本
, \1 g3 C: R# ?- ^
! P" t/ e! ]& c( P9 X [root@localhost libexec]# ./check_traffic.sh -h8 L) A+ X8 W: C; w6 K; T
Usage:
, m+ x0 ~% N. U$ S, j./check_traffic.sh [ -v ] [ -6 ] [ -r ] -V 1|2c|3 -C snmp-community -H host [ -L ] -I interface -w in,out-warning-value -c in,out-critical-value -K/M -B/b
' s. z0 m" c# ~) vExample:, f+ q+ B; g8 e& h# \0 ^# V
./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 4 -w 200,100 -c 300,200 -K -B
1 S9 A( s+ R( w6 r0 a" HOr -r to use Range Value Options:3 c/ f7 K) }& ?2 ~5 b
./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 4 -r -w 200-300,100-200 -c 100-400,50-250 -K -B Y4 ?5 W* v, \- ?
If you don't use -K/M -B/b options, default -K -b, corresponding to Kbps. (默认单位)
" d$ P6 O4 A! O' L X* `; k6 TMake sure that the check interval greater than 5 Seconds.) X- y) V h/ D7 ~+ B
Or modify the Min_Interval var in this file Line 180.
) D3 M2 |, L& |: g1 J! pAnd, if you want in Verbose mode, use -v, to check the debug messages in the file /tmp/check_traffic.$$.
# d* A5 ^6 `) {/ UOr use ./check_traffic.sh [ -v ] -V 1|2c|3 -C snmp-community -H host -L
" q+ \- ?4 k% P) B: Q! _To list all interfaces on specify host.; i: p2 j9 _+ J
% Z. D7 e1 {" G& Y4 f" x
[root@localhost libexec]# ./check_traffic.sh -V 2c -C public -H 192.168.2.6 -I 3 -w 200,300 -c 400,500 -K –B 定义in和out值分别超过200K、300K警告,超过400K,500k严重警告。' r2 F1 O& u& ]$ G
OK - It's the first time for this plugins run. We'll get the data from the next time.0 x) ~( d" }" ]& a t
第一次执行,history data file(/var/tmp/check_traffic_${Host}_${Interface}.hist_dat)不存在,因此会由此提示,可以忽略,再执行一次可以正正常获取
4 ~5 y, A/ n$ D( C. D. G) {% EOK - The Traffic In is 1.3750KB, Out is 0.0KB, Total is 1.3750KB. The Check Interval is 104s |In=1.3750KB;200;400;0;0 Out=0.0KB;300;500;0;0 Total=1.3750KB;500;900;0;0 Interval=104s;1200;1800;0;0
) @8 O! Y4 [- \9 S+ H5 O' y
0 I1 B9 j" ?# Z1 v8 d. B. A* a5. 在nagios的command文件里面定义check_traffic命令
9 q2 d; f0 z* y6 B1 Q
3 v4 y) a0 A Q1 I/ f- x3 I# 'check_traffic' command definition, P# s2 H) ^9 M& ]$ l
define command{7 Y. m4 |' D/ E, q
command_name check_traffic
# N [; ?* k4 _! q command_line $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -K -B 监控单位可以自定义# V4 Z% F* v- ?
}; e! B% u1 Q' Q# p" W3 k" _! ^7 f7 b
; k: l, P0 Y/ g1 f: `" \# x j _
6. 在nagios的监控对象cfg文件里面添加check_traffic t0 X" W) I# h. t1 J, v; P3 n6 N
- u8 v; R7 i1 Wdefine service{
# ?0 W5 D% K: D- ~# l0 i2 z use generic-service+ g$ q2 W4 t+ m/ _/ M& [
host_name linux* \% L% [6 V) h! _- t7 Z7 V" R' g7 @
service_description traffic
8 |6 [9 ~6 ^" L4 a; l check_command check_traffic!3!200,300!400,500 监控eth1网卡1 o2 f( t& k" a/ S1 \- }$ P0 m
} #与定义的宏对应添加参数值 |
|