网络状态监控

需求

        监控IDC机房网络质量情况,本地区到其他地区,其他地区到本节点,或者各省市时间网络、运营商网络状态,监视网络性能,包括常规的 ping,用 fping、echoping、tracert 监视 www 服务器性能,监视 dns 查询性能,监视 ssh 性能等。底层也是 rrdtool 做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示。

        Smokeping。最新版本的 Smokeping 支持多个节点的检测结果从一个图上画出来

准备工作

安装yum源

1
2
# rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm               
# rpm –Uvh http://mirrors.neusoft.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm

安装依赖包

1
2
# yum –y install perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI perl-FCGI perl-CGI-SpeedCGI perl-Time-HiRes perl-ExtUtils-MakeMaker perl-RRD-Simple rrdtool rrdtool-perl curl fping echo
ping httpd httpd-devel gcc make wget libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel mod_fastcgi

安装smokeping

下载

1
# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz 这里下载的最新版

安装FCGI

1
2
3
4
# tar zxf CGI-4.33.tar.gz
# cd CGI-4.33
# perl Makefile.PL
# make && make install

安装Config-Grammar

1
2
3
4
# tar zxf Config-Grammar-1.10.tar.gz
# cd Config-Grammar-1.10
# perl Makefile.PL
# make && make install

安装ExtUtils-MakeMaker

1
2
3
4
# tar zxf ExtUtils-MakeMaker-7.24.tar.gz
# cd ExtUtils-MakeMaker
# perl Makefile.PL
# make && make install

安装Simple

1
2
3
4
5
# tar zxf Test-Simple-1.302056.tar.gz
# cd Test-Simple-1.302056
# perl Makefile.PL
# make && make install
`

安装Net-OpenSSH

1
2
3
4
# tar zxf Net-OpenSSH-0.73.tar.gz
# cd Net-OpenSSH-0.73
# perl Makefile.PL
# make && make install

安装Net-SNMP

1
2
3
4
# tar Net-SNMP-v6.0.1.tar.gz
# cd Net-SNMP-v6.0.1
# perl Makefile.PL
# make && make install

安装perl-ldap

1
2
3
# tar zxf perl-ldap-0.65.tar.gz
# cd perl-ldap-0.65
# ./install-nomake

安装Net-DNS

1
2
3
4
# tar zxf Net-DNS-1.06.tar.gz
# cd Net-DNS-1.06
# perl Makefile.PL
# make && make install

安装IO-Tty

1
2
3
4
# tar IO-Tty-1.12.tar.gz
# cd IO-Tty-1.12
# perl Makefile.PL
# make && make install

安装libwww-perl

1
2
3
4
# tar zxf libwww-perl-6.15.tar.gz
# cd libwww-perl-6.15
# perl Makefile.PL
# make && make install

安装smokeping

1
2
3
4
# tar zxf smokeping-2.6.11.tar.gz
# cd smokeping-2.6.11
# ./configure --prefix=/usr/local/smokeping
# /usr/bin/gmake install

上面是手动安装,针对网络不能翻墙。也可以采取smokeping一键安装的方式进行安装

smokeping一键安装

安装smokeping

1
2
3
4
5
# tar zxf smokeping-2.6.11.tar.gz
# cd smokeping-2.6.11
# ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
# ./configure --prefix=/usr/local/smokeping
# /usr/bin/gmake install

配置smkeping

创建cache、data、var目录

1
2
# cd /usr/local/smokeping/
# mkdir {cache,data,var}

创建日志文件

1
# touch /var/log/smokeping.log

赋权限

1
2
3
# chown apache:apache cache/ data/ var/
# chown apache:apache /var/log/smokeping.log
# chmod 755 cache/ data/ var/ #这里也要赋权限,会影响图片无法加载

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# /usr/local/smokeping/htdocs
# cp -arp smokeping.fcgi.dist smokeping.fcgi
# cd ../etc/
# cp -arp config.dist config
# chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
# vim config
*** General ***
owner = Peter Random
contact = some@address.nowhere
mailhost = my.mail.host
sendmail = /usr/sbin/sendmail
# NOTE: do not put the Image Cache below cgi-bin
# since all files under cgi-bin will be executed ... this is not
# good for images.
imgcache = /usr/local/smokeping/cache
imgurl = http://172.16.1.100/cache #这里如果不配置正确,会影响后面出图,这里一个坑
datadir = /usr/local/smokeping/data
piddir = /usr/local/smokeping/var
cgiurl = http://172.16.1.100/smokeping/smokeping.cgi
#cgiurl = http://some.url/smokeping.cgi
smokemail = /usr/local/smokeping/etc/smokemail.dist
tmail = /usr/local/smokeping/etc/tmail.dist
# specify this to get syslog logging
syslogfacility = local0
# each probe is now run in its own process
# disable this to revert to the old behaviour
# concurrentprobes = no
*** Alerts ***
to = alertee@address.somewhere
from = smokealert@company.xy
+someloss
type = loss
# in percent
pattern = >0%,*12*,>0%,*12*,>0%
comment = loss 3 times in a row
*** Database ***
step = 60 #检测时间,默认300
pings = 20

配置文件上述修改带有注视部分,其他参数参考官方,而且都能看懂。后面有很多配置不全部贴出来

配置apache

配置httpd.conf

在DocumentRoot “/var/www/html”这行增加如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# vim /etc/httpd/conf/httpd.conf
Alias /cache "/usr/local/smokeping/cache"
Alias /cropper "/usr/local/smokeping/htdocs/cropper"
Alias /smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi"
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
Order allow,deny
Allow from all
AuthName "Smokeping"
AuthType Basic
AuthUserFile /usr/local/smokeping/htdocs/htpasswd
Require valid-user
DirectoryIndex smokeping.fcgi
</Directory>

apache登录认证

1
2
# /usr/local/smokeping/htdocs
# htpasswd -c /usr/local/smokeping/htdocs/htpasswd admin #回车设置admin账户的密码

安装网页支持的中文字体

1
# yum -y install wqy-zenhei-fonts.noarch

smokeping开机脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# vim /etc/init.d/smokeping
#!/bin/bash
PIDFILE=/usr/local/smokeping/var/smokeping.pid
SMOKEPING=/usr/local/smokeping/bin/smokeping
ERROR=0
RUNNING=0
ARGV="$@"
if [ "x$ARGV" = "x" ] ; then
ARGS=help
fi
for ARG in $@ $ARGS
do
if [ -f $PIDFILE ] ; then
PID=`cat $PIDFILE`
if kill -0 $PID 2>/dev/null ; then
# smokeping is running
RUNNING=1
else
# smokeping not running but PID file exists => delete PID file
rm -f $PIDFILE
RUNNING=0
fi
else
# smokeping (no pid file) not running
RUNNING=0
fi
case $ARG in
start)
if [ $RUNNING -eq 0 ] ; then
if $SMOKEPING > /dev/null; then
echo "$0 $ARG: smokeping started"
else
echo "$0 $ARG: smokeping could not be started"
ERROR=1
fi
else
echo "$0 $ARG: smokeping is running with PID $PID"
ERROR=2
fi
;;
stop)
if [ $RUNNING -eq 1 ] ; then
if kill $PID ; then
echo "$0 $ARG: smokeping ($PID) stopped"
rm $PIDFILE
else
echo "$0 $ARG: smokeping could not be stopped"
ERROR=3
fi
else
echo "$0 $ARG: smokeping not running"
ERROR=4
fi
;;
restart)
if [ $RUNNING -eq 1 ] ; then
if $SMOKEPING --restart > /dev/null; then
echo "$0 $ARG: smokeping restarted"
else
echo "$0 $ARG: smokeping could not be started"
ERROR=5
fi
else
$0 start
fi
;;
strace_debug)
rm -f /tmp/strace_smokeping
if [ $RUNNING -eq 1 ] ; then
if strace -o/tmp/strace_smokeping $SMOKEPING --restart >/dev/null; then
echo "$0 $ARG: smokeping restarted with strace debug in /tmp/strace_smokeping"
else
echo "$0 $ARG: smokeping strace debug could not be started"
ERROR=6
fi
else
if strace -o/tmp/strace_smokeping $SMOKEPING >/dev/null; then
echo "$0 $ARG: smokeping started with strace debug in /tmp/strace_smokeping"
else
echo "$0 $ARG: smokeping strace debug could not be started"
ERROR=7
fi
fi
;;
status)
if [ $RUNNING -eq 1 ] ; then
echo "$0 $ARG: smokeping is running with PID ($PID)"
else
echo "$0 $ARG: smokeping is not running"
fi
;;
*)
echo "usage: $0 (start|stop|restart|status|strace_debug|help)"
cat
start - start smokeping
stop - stop smokeping
restart - restart smokeping if running or start if not running
status - show status if smokeping is running or not
help - this screen
EOF
;;
esac
done
exit $ERROR

# chmod +x /etc/init.d/smokeping

启动服务

1
2
# service httpd start
# /etc/init.d/smokeping start

打开浏览器测试http://{ip}/smokeping 会提示输入用户和密码
img
img

配置文件添加

配置文件添介绍,在配置文件里面+表示一级++表示二级+++三级
本次添加的内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
+ Other
menu = 其他网络监控
title = 其他所有网络监控列表
++ dianxin
menu = 电信网络监控
title = 电信网络监控列表
host = /Other/dianxin/dianxin-hlj /Other/dianxin/dianxin-gd /Other/dianxin/dianxin-gs /Other/dianxin/dianxin-sh /Other/dianxin/dianxin-sc /Other/dianxin/dianxin-cq /Other/dianxin/dianxin-gz /Other/dianxin/dianxin-ln /Other/dianxin/dianxin-zj /Other/dianxin/dianxin-sd /Other/dianxin/dianxin-hib /Other/dianxin/dianxin-ah /Other/dianxin/dianxin-hb /Other/dianxin/dianxin-jl /Other/dianxin/dianxin-jx
+++ dianxin-hlj
menu = 黑龙江电信
title = 黑龙江电信
alerts = someloss
#slaves = boomer slave2
host = 219.150.32.132
+++ dianxin-gd
menu = 广东电信
title = 广东电信
alerts = someloss
#slaves = boomer slave2
host = 202.96.134.133
+++ dianxin-gs
menu = 甘肃电信
title = 甘肃电信
alerts = someloss
#slaves = boomer slave2
host = 202.100.64.68
+++ dianxin-sh
menu = 上海电信
title = 上海电信
alerts = someloss
#slaves = boomer slave2
host = 202.96.209.5
+++ dianxin-sc
menu = 四川电信
title = 四川电信
alerts = someloss
host = 218.6.145.111
+++ dianxin-cq
menu = 重庆电信
title = 重庆电信
alerts = someloss
host = 61.128.128.68
+++ dianxin-gz
menu = 贵州电信
title = 贵州电信
alerts = someloss
host = 202.98.192.68
+++ dianxin-ln
menu = 辽宁电信
title = 辽宁电信
alerts = someloss
host = 219.149.6.99
+++ dianxin-zj
menu = 浙江电信
title = 浙江电信
alerts = someloss
host = 202.96.96.68
+++ dianxin-sd
menu = 山东电信
title = 山东电信
alerts = someloss
host = 222.173.95.53
+++ dianxin-hib
menu = 湖北电信
title = 湖北电信
alerts = someloss
host = 202.103.0.68
+++ dianxin-ah
menu = 安徽电信
title = 安徽电信
alerts = someloss
host = 220.178.75.134
+++ dianxin-hb
menu = 河北电信
title = 河北电信
alerts = someloss
host = 202.99.160.68
+++ dianxin-jl
menu = 吉林电信
title = 吉林电信
alerts = someloss
host = 219.149.194.55
+++ dianxin-jx
menu = 江西电信
title = 江西电信
alerts = someloss
host = 202.101.224.68
#+++ dianxin-multi
#menu = 多个电信网络监控列表
#title = 多个电信网络监控列表
#alerts = someloss
#slaves = boomer slave2
#host = /Other/dianxin/dianxin-hlj /Other/dianxin/dianxin-gd /Other/dianxin/dianxin-gs /Other/dianxin/dianxin-sh
#
++ liantong
menu = 联通网络监控
title = 联通网络监控列表
host = /Other/liantong/liantong-hlj /Other/liantong/liantong-gd /Other/liantong/liantong-gs /Other/liantong/liantong-sh /Other/liantong/liantong-sc /Other/liantong/liantong-cq /Other/liantong/liantong-gz /Other/liantong/liantong-ln /Other/liantong/liantong-zj /Other/liantong/liantong-sd /Other/liantong/liantong-hib /Other/liantong/liantong-ah /Other/liantong/liantong-hb /Other/liantong/liantong-jl /Other/liantong/liantong-jx
+++ liantong-hlj
menu = 黑龙江联通
title = 黑龙江联通
alerts = someloss
#slaves = boomer slave2
host = 202.97.224.68
+++ liantong-gd
menu = 广东联通
title = 广东联通
alerts = someloss
#slaves = boomer slave2
host = 221.4.66.66
+++ liantong-gs
menu = 甘肃联通
title = 甘肃联通
alerts = someloss
#slaves = boomer slave2
host = 221.7.34.10
+++ liantong-sh
menu = 上海联通
title = 上海联通
alerts = someloss
#slaves = boomer slave2
host = 210.22.70.3
+++ liantong-sc
menu = 四川联通
title = 四川联通
alerts = someloss
host = 119.6.6.6
+++ liantong-cq
menu = 重庆联通
title = 重庆联通
alerts = someloss
host = 221.7.92.98
+++ liantong-gz
menu = 贵州联通
title = 贵州联通
alerts = someloss
host = 221.13.30.242
+++ liantong-ln
menu = 辽宁联通
title = 辽宁联通
alerts = someloss
host = 124.161.97.234
+++ liantong-zj
menu = 浙江联通
title = 浙江联通
alerts = someloss
host = 221.12.33.227
+++ liantong-sd
menu = 山东联通
title = 山东联通
alerts = someloss
host = 202.102.152.3
+++ liantong-hib
menu = 湖北联通
title = 湖北联通
alerts = someloss
host = 218.104.111.114
+++ liantong-ah
menu = 安徽联通
title = 安徽联通
alerts = someloss
host = 211.91.88.129
+++ liantong-hb
menu = 河北联通
title = 河北联通
alerts = someloss
host = 202.99.160.68
+++ liantong-jl
menu = 吉林联通
title = 吉林联通
alerts = someloss
host = 202.98.5.6
+++ liantong-jx
menu = 江西联通
title = 江西联通
alerts = someloss
host = 220.248.192.12
#+++ liantong-multi
#menu = 多个联通网络监控列表
#title = 多个联通网络监控列表
#alerts = someloss
#slaves = boomer slave2
#host = /Other/liantong/liantong-hlj /Other/liantong/liantong-gd /Other/liantong/liantong-gs /Other/liantong/liantong-sh
++ yidong
menu = 移动网络监控
title = 移动网络监控列表
host = /Other/yidong/yidong-hlj /Other/yidong/yidong-gd /Other/yidong/yidong-gs /Other/yidong/yidong-sh /Other/yidong/yidong-sc /Other/yidong/yidong-cq /Other/yidong/yidong-gz /Other/yidong/yidong-ln /Other/yidong/yidong-zj /Other/yidong/yidong-sd /Other/yidong/yidong-hib /Other/yidong/yidong-ah /Other/yidong/yidong-hb
+++ yidong-hlj
menu = 黑龙江移动
title = 黑龙江移动
alerts = someloss
#slaves = boomer slave2
host = 211.137.241.34
+++ yidong-gd
menu = 广东移动
title = 广东移动
alerts = someloss
#slaves = boomer slave2
host = 211.137.241.34
+++ yidong-gs
menu = 甘肃移动
title = 甘肃移动
alerts = someloss
#slaves = boomer slave2
host = 218.203.160.194
+++ yidong-sh
menu = 上海移动
title = 上海移动
alerts = someloss
#slaves = boomer slave2
host = 117.131.0.22
+++ yidong-sc
menu = 四川移动
title = 四川移动
alerts = someloss
host = 211.137.96.205
+++ yidong-cq
menu = 重庆移动
title = 重庆移动
alerts = someloss
host = 218.201.4.3
+++ yidong-gz
menu = 贵州移动
title = 贵州移动
alerts = someloss
host = 211.139.1.3
+++ yidong-ln
menu = 辽宁移动
title = 辽宁移动
alerts = someloss
host = 218.59.181.182
+++ yidong-zj
menu = 浙江移动
title = 浙江移动
alerts = someloss
host = 211.140.10.2
+++ yidong-sd
menu = 山东移动
title = 山东移动
alerts = someloss
host = 211.137.191.26
+++ yidong-hib
menu = 湖北移动
title = 湖北移动
alerts = someloss
host = 211.137.76.68
+++ yidong-ah
menu = 安徽移动
title = 安徽移动
alerts = someloss
host = 211.138.180.2
+++ yidong-hb
menu = 河北移动
title = 河北移动
alerts = someloss
host = 211.98.2.4
#+++ yidong-multi
#menu = 多个移动网络监控列表
#title = 多个移动网络监控列表
#alerts = someloss
#slaves = boomer slave2
#host = /Other/yidong/yidong-hlj /Other/yidong/yidong-gd /Other/yidong/yidong-gs /Other/yidong/yidong-sh
++ jiaoyu
menu = 教育网络监控
title = 教育网络监控列表
host = /Other/jiaoyu/jiaoyu-qh /Other/jiaoyu/jiaoyu-sh /Other/jiaoyu/jiaoyu-wh /Other/jiaoyu/jiaoyu-hn
+++ jiaoyu-qh
menu = 清华大学
title = 清华大学
alerts = someloss
#slaves = boomer slave2
host = 166.111.8.28
+++ jiaoyu-sh
menu = 上海交大
title = 上海交大
alerts = someloss
#slaves = boomer slave2
host = 202.112.26.34
+++ jiaoyu-wh
menu = 武汉科技大学
title = 武汉科技大学
alerts = someloss
#slaves = boomer slave2
host = 202.114.240.6
+++ jiaoyu-hn
menu = 华南农业大学
title = 华南农业大学
alerts = someloss
#slaves = boomer slave2
host = 202.116.160.33
#+++ jiaoyu-multi
#menu = 多个教育网络监控列表
#title = 多个教育网络监控列表
#alerts = someloss
#slaves = boomer slave2
#host = /Other/jiaoyu/jiaoyu-qh /Other/jiaoyu/jiaoyu-sh /Other/jiaoyu/jiaoyu-wh /Other/jiaoyu/jiaoyu-hn
坚持原创技术分享,您的支持将鼓励我继续创作!
0%