SmokePing

SmokePing keeps track of your network latency:
  • Best of breed latency visualisation.
  • Interactive graph explorer.
  • Wide range of latency measurment plugins.
  • Master/Slave System for distributed measurement.
  • Highly configurable alerting system.
  • Live Latency Charts with the most ‘interesting’ graphs.
  • Free and OpenSource Software written in Perl written by Tobi Oetiker, the creator of MRTG and RRDtool
  • SmokePing Documentation

smokeping-2.6.8 安装

smokeping 2.4.2 的参照这篇文档就好了,可以把 chroot 安装在他默认的地方,这样需要修改的地方就大大减少了。

下面这个是 2.6.8 的记录,简单记录一下步骤,选择性的解释:
# rpm -ivh http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.x86_64.rp
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
# yum makecache
# yum install rrdtool fping  echoping curl dig
# yum install perl  perl-CPAN rrdtool-perl

# cpan
> install FCGI
> install FCGI::ProcManager
> install CGI::Fast
> install Config::Grammar
> install Digest::HMAC_MD5
> install Net::Telnet
> install Net::OpenSSH
> install Net::SNMP
> install Net::DNS
> install Getopt::Long
> install IO::All
> install Socket
> install LWP

# wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz -O /usr/local/src/smokeping-2.6.8.tar.gz ; cd /usr/local/src/
# tar zxvf smokeping-2.6.8.tar.gz
# cd smokeping-2.6.8
# ./configure --prefix=/usr/local/smokeping
# gmake install

在进行编译的时候,会出现一些如下的信息,有助于 debug,可以留意。

checking checking for gnu make availablility… /usr/bin/gmake is GNU make
checking checking for perl module ‘RRDs’… Ok
checking checking for perl module ‘FCGI’… Ok
checking checking for perl module ‘CGI’… Ok
checking checking for perl module ‘CGI::Fast’… Ok
checking checking for perl module ‘Config::Grammar’… Failed
checking checking for perl module ‘Digest::HMAC_MD5’… Ok
checking checking for perl module ‘LWP’… Ok

上面安装 cpan 的步骤其实在源文件里面已经有了:
# pwd
/usr/local/src/smokeping-2.6.8/setup
# ll build-perl-modules.sh
-rwxr-xr-x. 1 jaseywang jaseywang 287 Oct  5  2011 build-perl-modules.sh

# cd /usr/local/smokeping/etc
# for foo in *.dist; do cp $foo `basename $foo .dist`; done

or
# find . -name '*.dist' -print -execdir sh -c 'mv {} $(basename {} .dist)' \;
# cd ..
# mkdir -p ./{data,cache,var}
# chmod -R 777 cache
# chmod 600 ./etc/smokeping_secrets
# ln -s htdocs/cropper/

检查语法:
# /usr/local/smokeping/bin/smokeping --check

开启 debug 模式,运行完退出:
# /usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --debug

启动,将 log 输出至 smokeping.log 文件中:
# /usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --logfile=/usr/local/logs/smokeping.log

init 文件:
# wget http://oss.oetiker.ch/smokeping/pub/contrib/smokeping-start-script -O /etc/init.d/smokeping
# chmod a+x /etc/init.d/smokeping
# sed s@PIDFILE=/usr/local/smokeping/etc/data/smokeping.pid@PIDFILE=/usr/local/smokeping/var/smokeping.pid@ /etc/init.d/smokeping

nginx 部分:
# wget http://code.google.com/p/autonagios/source/browse/trunk/autonagios-20100103/files/nginx-fcgi.txt -O /etc/nginx-fcgi
# chmod a+x /etc/nginx-fcgi
# /etc/nginx-fcgi -l /var/log/nginx-fcgi.log -pid /var/run/nginx-fcgi.pid -S /var/run/nginx-fcgi.sock
# cd /usr/local/nginx
# cat conf/nginx.conf


server {
listen       80;
server_name  localhost;
root   /usr/local/smokeping/;

location ~ .*\.cgi$ {
root   /usr/local/smokeping/htdocs/;
fastcgi_pass unix:/var/run/nginx-fcgi.sock;
fastcgi_index   index.cgi;
include fastcgi_params;
fastcgi_param   SCRIPT_FILENAME /usr/local/smokeping/htdocs$fastcgi_script_name;
}

# ./sbin/nginx  -t -c conf/nginx.conf
# ./sbin/nginx -s reload
# curl ip/smokeping.cgi

上面那个是 RH 的版本,Ubuntu 的很简单,以 10.04 为例,官方还是 2.3.6-5 的版本,自己下 deb 包安装:
# wget http://mirrors.163.com/ubuntu/pool/universe/s/smokeping/smokeping_2.6.8-1.1_all.deb
# apt-get install libcgi-fast-perl libconfig-grammar-perl libdigest-hmac-perl libfcgi-perl libio-socket-inet6-perl libjs-cropper libperl5.10 librrd4 librrds-perl libsnmp-session-perl libsocket6-perl perl perl-base perl-modules ttf-dejavu ttf-dejavu-extra libperl5.10 perl perl-base perl-modules fping
# dpkg -i smokeping_2.6.8-1.1_all.deb

修改下 config.d/ 下面的文件,先检查一下有没有语法错误,再 debug 一遍,最后以 daemon 的方式启动:
# smokeping  --config /etc/smokeping/config --check
# smokeping  --config /etc/smokeping/config --debug
# smokeping  --config /etc/smokeping/config --debug-daemon

关于 smokeping 的相关语法,官方文档说的很详细,不在此记录。这里有个别人写的安装脚本,比较老,对目前的版本不是很适合,不过可以供参考学习。

SP 相比其他,最突出的就是其 alert 做的很好,其阈值的设置可以具体到触发几次,丢包几次,丢包率达到多少的粒度去报警,具体的看配置文件的里面的几个注释应该就能懂了。每次修改完,记得使用 –check 检查一遍有没有语法错误再启动。

ref:
http://tomoconnor.eu/blogish/smokeping-nginx/
http://blog.icelandic.net/2011/07/17/smokeping-on-nginx/
http://ai.net.nz/gettinghelp/how-do-i/centos-servers/67-5-packages-04-smokeping.html

http://www.howtoforge.com/monitoring-network-latency-with-smokeping-ubuntu-9.04

smokeping-2.6.8 主从部署

除了上文说的 SP 在报警方面比较强大之外,M/S 也是 SP 一个比较强大的地方,这样,从各地收集的数据更能客观的说明情况。

slave
# hostname
slave1.jaseywang.me
# cd /etc/smokeping
# echo "helloworld" > slavesecrets.conf
# chmod 600 !$
# chown smokeping !$
# cat /etc/default/smokeping

MODE=slave
MASTER_URL=http://master_ip/smokeping/smokeping.cgi
SHARED_SECRET=/etc/smokeping/slavesecrets.conf
SLAVE_NAME=slave1.jaseywang.me

master:
# cd /etc/smokeping
# echo "helloworld" > slavesecrets.conf
# chmod 600 !$
# chown smokeping !$
# echo "slave1.jaseywang.me:helloworld" > smokeping_secrets
# chown www-data !$
# chmod 600 !$
# cat /etc/default/smokeping

MODE=master
# cat config.d/Slaves
*** Slaves ***
secrets=/etc/smokeping/smokeping_secrets
+test.jaseywang.me
display_name=test.jaseywang.me
color=00ff00
# head config.d/Targets
*** Targets ***

slaves = test.jaseywang.me

在启动过程中,会出现类似如下的一些 error:
WARNING: Opening secrets file /etc/smokeping/smokeping_secrets: Permission denied
WARNING: No targets found for slave ‘slave1.jaseywang.me’
ERROR: we did not get config from the master. Maybe we are not configured as a slave for any of the targets on the master ?
ERROR: the shared secret file (/etc/smokeping/slavesecrets.conf) is world-readable or writable at /usr/share/perl5/Smokeping.pm line 4117.

原因无非是上面哪个步骤做的有问题。正确的启动 log 如下:
* Starting latency logger daemon smokeping                                                                                                                    Sent data to Server and got new config in response.
[ OK ]
# ps axu | grep sm
root        83  0.0  0.0      0     0 ?        SN   Dec06   0:00 [ksmd]
109      31537  0.3  0.1 143980 27100 ?        Ss   00:38   0:00 /usr/bin/perl /usr/sbin/smokeping –config=/etc/smokeping/config –master-url http://master_ip/smokeping/smokeping.cgi –shared-secret /etc/smokeping/slavesecrets.conf –slave-name slave1.jaseywang.me –cache-dir /var/lib/smokeping –pid-dir /var/run/smokeping
109      31538  0.0  0.1 143980 27000 ?        S    00:38   0:00 /usr/sbin/smokeping [Curl]
109      31540  0.0  0.1 143980 27000 ?        S    00:38   0:00 /usr/sbin/smokeping [DNS]
109      31541  0.0  0.1 143980 27000 ?        S    00:38   0:00 /usr/sbin/smokeping [FPing]
root     31561  0.0  0.0   7624   928 pts/0    R+   00:38   0:00 grep –color=auto sm

以上是在 ubuntu 上,有 /etc/default/smokeping 文件,比较省心,如果是 CentOS 等,则需要像下面这样手动启动:
# /usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --master-url http://master_ip/smokeping/smokeping.cgi --shared-secret /usr/local/smokeping/etc/slavesecrets.conf --slave-name test.jaseywang.me --cache-dir /usr/local/smokeping/cache/ --pid-dir /usr/local/smokeping/var/
Sent data to Server and got new config in response.
### parsing dig output…OK
### assuming you are using an fping copy reporting in milliseconds
Note: logging to syslog as local0/info.
Daemonizing /usr/local/smokeping/bin/smokeping …

ref:

https://nsrc.org/workshops/2012/menog-dns-dnssec/attachment/wiki/References/sample-smokeping-master-slave.txt

Smokeping2.6.9配置实例

1、Install(smokeping-2.6.9.tar.gz )
http://oss.oetiker.ch/smokeping/doc/smokeping_install.en.html

apache fastcgi
Ref: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
# wget http://mirror.bit.edu.cn/apache//httpd/mod_fcgid/mod_fcgid-2.3.9.tar.gz
# tar zxvf mod_fcgid-2.3.9.tar.gz
# cd mod_fcgid-2.3.9
# ./configure.apxs
注意:
(1) 若没有apxs工具(apache是通过yum安装的话),请安装httpd-devel
# yum install httpd-devel

(2) Apache cgi模块
LoadModule cgi_module modules/mod_cgi.so
LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so
LoadModule cgid_module modules/mod_cgid.so #若不启用,fcgi只显示源码
2、Config
1) smokeping init script
# wget http://oss.oetiker.ch/smokeping/pub/contrib/smokeping-start-script -O /etc/init.d/smokeping

2) smokeping configuration for apache
[root@cactiserver smokeping]# cat /etc/httpd/conf.d/smokeping.conf
Alias /smokeping/ “/home/smokeping/htdocs/”
Alias /cache/ “/home/smokeping/cache/”
<Directory “/home/smokeping/htdocs”>
Options FollowSymLinks ExecCGI
AllowOverride None
AddHandler cgi-script .fcgi
Order allow,deny
Allow from all
</Directory>

发表评论