smokeping是对IDC网络质量,稳定性等最好的检测工具,包括常规的 ping,dig,echoping,curl等,可以 监视 www 服务器性能,监视 dns 查询性能,监视 ssh 性能等。Smokeping是rrdtool的作者Tobi Oetiker的作品,所以底层也是 rrdtool 做支持。smokeping是一个很老的开源项目了,不过考虑到现网以下两方面的需求,感觉还是有必要部署的。1、针对虚拟化平台主机重启速度较快,普通的监控平台可能敏感度不够;2、业务和网络部门经常有对网络质量和页面访问速度对比的需求。
一、smokeping的安装条件
smokeping安装前需要准备的相关包可以参看官方页面:http://oss.oetiker.ch/smokeping/doc/smokeping_install.en.html ,所需要具体如下(其中带有optional 的选项为可选包):
RRDtool 1.2.x or later
FPing (optional)
EchoPing (Optional)
Curl (Optional)
dig (Optional)
SSH (Optional)
Webserver
Perl 5.8.8 or later(对应的模块如下)
FCGI
CGI, CGI::Fast
Config::Grammar
LWP
Socket6 (optional)
Net::Telnet (optional)
Net::OpenSSH (optional)
Net::DNS (optional)
Net::LDAP (optional)
IO::Socket::SSL (optional)
Authen::Radius (optional)
在centos环境下,上述包基本都可以通过增加第三方源epel 进行安装完整。我测试时安装了如下包:
[root@361way ~]# yum install rrdtool fping wget dig curl bind-utils gcc make perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-FCGI perl-RRD-Simple perl-CPAN rrdtool-perl perl-CGI-SpeedCGI perl-ExtUtils-MakeMaker
由于我是使有的nginx整合,如果使有apache,还需要安装如下包:
# yum install mod_fcgid httpd httpd-devel
二、安装smokeping
1、安装smokeping
[root@361way src]# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz
[root@361way src]# tar xvf smokeping-2.6.11.tar.gz
[root@361way src]# cd smokeping-2.6.11
[root@361way smokeping-2.6.11]# ./configure --prefix=/opt/smokeping
[root@361way smokeping-2.6.11]# gmake install
[root@361way smokeping-2.6.11]# make install
在进行configure配置时,如果发现perl 环境有缺少的包,会报如下错误:
** Aborting Configure ******************************
If you know where perl can find the missing modules, set
the PERL5LIB environment variable accordingly.
FIRST though, make sure that 'perl' starts the perl
binary you want to use for SmokePing.
Now you can install local copies of the missing modules
by running
./setup/build-perl-modules.sh /opt/smokeping/thirdparty
The RRDs perl module is part of RRDtool. Either use the rrdtool
package provided by your OS or install rrdtool from source.
If you install from source, the RRDs module is located
PREFIX/lib/perl
出现上面的错误时,可以通过执行./setup/build-perl-modules.sh /opt/smokeping/thirdparty 安装所需要的包(需要能连接外网)。安装完成后,再执行后面的gmake和make install 的操作。
2、创建数据文件目录
# cd /opt/smokeping
# mkdir data var cache
# chown -R www:www data cache
nginx是用www用户执行的,所以这里相应的数据目录要有可写的权限 。
3、创建启停脚本文件
在服务启动之前,需要先配置config配置文件,配置这部分可以参看本篇第三部分。
# wget http://www.111cn.net/wp-content/uploads/2016/05/smokeping.txt
# mv smokeping.txt /etc/init.d/smokeping
# chmod 755 /etc/init.d/smokeping
如需要配置开机自启动,还需要使用chconfig 命令执行如下操作:
# chkconfig –add smokeping
# chkconfig smokeping on
4、配置文件权限修改
smokeping_secrets主要是用于配置master/slave通信时的密钥文件,单主机运行smokeping时不涉及
# cd /opt/smokeping/etc/
# for foo in *.dist; do cp $foo `basename $foo .dist`; done
# chmod 600 /opt/smokeping/etc/smokeping_secrets.dist
三、smokeping配置文件
smokeping配置可以分为七部分,如下:
第一部分 General 属于基本配置。值得注意的地方有imgcache和imgurl这两个参数,要注意一下,和apache配置相关联,如果配置不好的话,打开web的时候图片会显示不出来;
第二部分Alerts 是属于报警配置;
第三部分 Database RRD数据库配置。step和pings这两个参数要在启动smokeping之前配置好,如果在smokeping启动后再配置这两个参数,需要把原来的rrd文件都删除,然后再启动smokeping才可以。所以这个一定要先配置好。默认是step=300 pings=20 是每300s内执行20次ping的动作;
第四部分Presentation 是关于网络状态的一些配置和解释,基本不需要更改;
第五部分Porbes 指针配置,我们一般只用到fping所以就只要以下配置就可以了,确定路径是否正确,这里还可以设置fping包的大小,参数是packetsize;
第六分部Slaves 主从关系里面的从服务器相关配置,smokeping里面从服务器只需要安装好就可以了,不需要配置,smokeping的所有配置都是在master上面设置。这里主要设置好secrets密码文件和从服务器配置就可以了;
第七部分 Targets 目标配置。在这里可以单独配置一台服务器的监控情况,需要从slave服务器上取值的配置也是在这里配置。我已经用注释说明的很清楚了。这里要注意一下。+代表一级菜单 +下面的++是继承上面的+成为二级菜单。 而且可以有多个一级菜单和二级菜单。
config配置示例如下:
# cat 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 = /opt/smokeping/cache
imgurl = cache
datadir = /opt/smokeping/data
piddir = /opt/smokeping/var
#cgiurl = http://192.168.0.110/smokeping/smokeping.cgi
cgiurl = http://192.168.0.110/smokeping.fcgi //这个地址很重要
smokemail = /opt/smokeping/etc/smokemail
tmail = /opt/smokeping/etc/tmail
# 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 = 300
step = 60
pings = 20
# consfn mrhb steps total
AVERAGE 0.5 1 1008
AVERAGE 0.5 12 4320
MIN 0.5 12 4320
MAX 0.5 12 4320
AVERAGE 0.5 144 720
MAX 0.5 144 720
MIN 0.5 144 720
*** Presentation ***
template = /opt/smokeping/etc/basepage.html.dist
charset = utf-8
+ charts
menu = Charts
title = The most interesting destinations
++ stddev
sorter = StdDev(entries=>4)
title = Top Standard Deviation
menu = Std Deviation
format = Standard Deviation %f
++ max
sorter = Max(entries=>5)
title = Top Max Roundtrip Time
menu = by Max
format = Max Roundtrip Time %f seconds
++ loss
sorter = Loss(entries=>5)
title = Top Packet Loss
menu = Loss
format = Packets Lost %f
++ median
sorter = Median(entries=>5)
title = Top Median Roundtrip Time
menu = by Median
format = Median RTT %f seconds
+ overview
width = 600
height = 50
range = 10h
+ detail
width = 600
height = 200
unison_tolerance = 2
"Last 3 Hours" 3h
"Last 30 Hours" 30h
"Last 10 Days" 10d
"Last 400 Days" 400d
#+ hierarchies
#++ owner
#title = Host Owner
#++ location
#title = Location
*** Probes ***
+ FPing
binary = /usr/sbin/fping
#$packetsize = 2000
*** Targets ***
probe = FPing
menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of xxx Company. \
Here you will learn all about the latency of our network.
+ Test
menu= 111cn.net smokeping测试
title=运维之路测试
#parents = owner:/Test/James location:/
++ 361way
menu = 361
title =111cn.net
alerts = someloss
host = www.111cn.net
++ 102Host
menu = 102
title = host102
host = 192.168.0.102
++ 200Host
menu = 200
title = host200
host = 192.168.0.200
++ 201Host
menu = 201
title = host201
host = 192.168.0.201
+ allHost
menu = allhost
title = All Host In One Graph
host = /Test/102Host /Test/200Host /Test/201Host
四、nginx反向代理smokping cgi 页面
nginx 与 smokping整合,需要用到cgi 运行的一个插件spawn-fcgi ,该包可以通过使用epel 源里下载安装到,直接yum -y install spawn-fcgi 即可。
1、创建smokeping-fastcgi 启动脚本
[root@361way smokeping]# cat /opt/smokeping/smokeping-fastcgi
#!/bin/sh
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9007 -P /var/run/smokeping-fastcgi.pid -u www -f /opt/smokeping/htdocs/smokeping.fcgi
2、配置smokeping-fastcgi 自动启动脚本
[root@361way ~]# cat /etc/init.d/smokeping-fastcgi
#!/bin/bash
FCGI_SCRIPT=/opt/smokeping/smokeping-fastcgi
FASTCGI_USER=www
PIDFILE=/var/run/smokeping-fastcgi.pid
RETVAL=0
case "$1" in
start)
$FCGI_SCRIPT
RETVAL=$?
;;
stop)
PID=`cat $PIDFILE`
kill -9 $PID $(pgrep -P $PID)
RETVAL=$?
;;
restart)
PID=`cat $PIDFILE`
kill -9 $PID $(pgrep -P $PID)
$FCGI_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: smokeping-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
3、nginx配置文件
有域名的可以将其中localhost替换成相应的域名
server {
listen 80;
server_name localhost;
location / {
root /opt/smokeping/htdocs/;
index index.html index.htm index.cgi;
}
location ~ .*\.fcgi$ {
root /opt/smokeping/htdocs/;
fastcgi_pass 127.0.0.1:9007;
include /opt/nginx/conf/fastcgi_params;
}
}
4、启动nginx与smokeping-fastcgi
# /etc/init.d/smokeping-fastcgi start
# /opt/nginx/sbin/nginx
在测试的时候发现一个问题:somkeping程序每一次重启时,smokeping-fastcgi 就会退出,也需要重启。所以最好给smokeping-fastcgi 开启一个守护进程,或者在smokeping 脚本中增加smokeping-fastcgi 重启的动作。
此时打开http://ip/smokeping.fcgi,即可以看到类似如下内容