linux下构建Smokeping网络监控平台
一. Smokeping 简介
1.1 Smokeping简介:
Smokeping 是rrdtool 的作者Tobi Oetiker 的作品,是用Perl 写的,主要是监视网络性能,包括常规的ping,用echoping监控www 服务器性能,监视dns 查询性能,监视ssh 性能等。底层也是rrdtool做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示。
1.2 Smokeping 架构组件
Smokeping 有以下组件组成:RRDtool、Fping、Echoping、Curl、Dig、SSh、Perl 模块,Perl、SpeedyCGI、Apache 等。
master/slave 的工作方式,可以在多个节点收集同一个监测点的数据;
1.3 Smokeping 相关资源
2> Smokeiping 相关文档下载:http://down.51cto.com/data/432197
3> Smokeiping 相关软件下载地址:http://down.51cto.com/data/432183
二.Smokeping 安装
[root@smokeping ~]# uname -a
Linux smokeping.junjie.com 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux
[root@smokeping ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
[root@smokeping ~]# perl -v
This is perl, v5.8.8 built for i386-linux-thread-multi
先暂时关闭iptables以及selinux刨除其他影响
构建本地yum数据库
[root@smokeping ~]# cat /etc/yum.repos.d/server.repo
name=Red Hat Enterprise Linux server
name=Red Hat Enterprise Linux vt
name=Red Hat Enterprise Linux cluster
name=Red Hat Enterprise Linux clusterstorage
[root@smokeping ~]#
[root@smokeping ~]# mkdir /mnt/cdrom
[root@smokeping ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@smokeping ~]# yum list all
RRDTool 是由Tobias Oetiker 开发的开源软件,它使用RRD(Round Rebin Databases)作为存储格式,Round robin 是一种处理定量数据以及当前元素指针的技术,RRDTool 主要用来跟踪对象的变化情况,生成改对象变化的趋势图。
[root@smokeping ~]# cd /root/smokeping/
[root@smokeping smokeping]# ls
cgilib-0.5.tar.gz
# 安装依赖的软件包:
[root@smokeping smokeping]# yum -y install freetype freetype-devel libpng libpng-devel gd gd-devel libxml2 libxml2-devel libiconv libiconv-devel pango pango-devel qpixman qpixman-devel glib glib-devel cairo cairo-devel libart* gettext gettext-devel libjpeg libjpeg-devel perl-XML-Simple.noarch perl-Crypt-SSLeay perl-Digest-HMAC
使rrdtool支持中文
[root@smokeping smokeping]# cat /etc/sysconfig/i18n
[root@smokeping smokeping]# export LANG="zh_CN.UTF-8"
[root@smokeping smokeping]# yum -y install fonts-chinese
[root@smokeping smokeping]# tar -zxvf rrdtool-1.4.4.tar.gz -C /usr/local/src/
[root@smokeping smokeping]# cd /usr/local/src/rrdtool-1.4.4/
[root@smokeping rrdtool-1.4.4]# ls
[root@smokeping rrdtool-1.4.4]# sed -i 's/setlocale(LC_NUMERIC, "C")/setlocale(LC_ALL, "zh_CN.UTF-8")/g' src/rrd_graph.c
[root@smokeping rrdtool-1.4.4]# sed -i 's/setlocale(LC_NUMERIC, old_locale)/setlocale(LC_ALL, old_locale)/g' src/rrd_graph.c
[root@smokeping rrdtool-1.4.4]# ./configure --prefix=/usr/local/rrdtool [root@smokeping rrdtool-1.4.4]# make && make install
[root@smokeping rrdtool-1.4.4]# cd /usr/local/rrdtool/bin/
[root@smokeping bin]# ll
-rwxr-xr-x 1 root root 95492 Jun 17 09:50 rrdcached
-rwxr-xr-x 1 root root 46362 Jun 17 09:50 rrdcgi
-rwxr-xr-x 1 root root 41520 Jun 17 09:50 rrdtool
-rwxr-xr-x 1 root root 207192 Jun 17 09:50 rrdupdate
[root@smokeping bin]# ./rrdtool
RRDtool 1.4.4 Copyright 1997-2010 by Tobias Oetiker <tobi@oetiker.ch>
Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv, dump, restore,
last, lastupdate, first, info, fetch, tune,
RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)
For more information read the RRD manpages
[root@smokeping bin]#
[root@smokeping bin]# cd /root/smokeping/
[root@smokeping smokeping]# tar -zxvf fping.tar.gz -C /usr/local/src/
[root@smokeping smokeping]# cd /usr/local/src/fping-2.4b2_to/
[root@smokeping fping-2.4b2_to]# ./configure
[root@smokeping fping-2.4b2_to]# make && make install
[root@smokeping fping-2.4b2_to]# ln -s /usr/local/fping/sbin/fping /usr/sbin/fping
[root@smokeping fping-2.4b2_to]#cd /root/smokeping/
[root@smokeping smokeping]#cd /usr/local/src/echoping-6.0.2
[root@smokeping echoping-6.0.2]# ./configure
[root@smokeping echoping-6.0.2]# make && make install
[root@smokeping echoping-6.0.2]# cd /root/smokeping/
[root@smokeping smokeping]# tar -zxvf cgilib-0.5.tar.gz -C /usr/local/src/
[root@smokeping smokeping]# cd /usr/local/src/cgilib-0.5/
cgi.5 cgiGetCookies.3 cgiRedirect.3 cookies.txt
cgi.c cgiGetValue.3 cgiSetHeader.3 CREDITS
cgiDebug.3 cgiGetVariables.3 cgiSetType.3 jumpto.c
cgiFree.3 cgi.h cgitest.c Makefile
cgiFreeList.3 cgiHeader.3 CHANGES readme
cgiGetCookie.3 cgiInit.3 cookies.c
[root@smokeping cgilib-0.5]# cp libcgi.a /usr/local/lib
[root@smokeping cgilib-0.5]# cp cgi.h /usr/include/
[root@smokeping cgilib-0.5]# cd /root/smokeping/
[root@smokeping smokeping]# tar -zxvf CGI-SpeedyCGI-2.22.tar.gz -C /usr/local/src/
[root@smokeping smokeping]# cd /usr/local/src/CGI-SpeedyCGI-2.22/
COPYING Makefile.PL contrib mod_speedycgi speedy_backend util
Changes README docs mod_speedycgi2 speedy_dump
MANIFEST README.html lib speedy src
[root@smokeping CGI-SpeedyCGI-2.22]# perl Makefile.PL
[root@smokeping CGI-SpeedyCGI-2.22]# make install
[root@smokeping ~]# yum install -y perl-libwww-perl perl-IO-Socket-SSL perl-Net-Telnet perl-Socket6 perl-Net-DNS perl-LDAP perl-libwww-perl perl-IO-Socket-SSL
[root@smokeping ~]# cd /root/smokeping/
[root@smokeping smokeping]# tar -zxvf smokeping-2.4.2.tar.gz -C /usr/local/src/
[root@smokeping smokeping]#mv /usr/local/src/smokeping-2.4.2/ /usr/local/smokeping
在smokeping的子目录中会发现很多“*.dist”命名的文件,这些文件使用的时候请将其改名为“*”并进行配置
[root@smokeping ~]# cd /usr/local/smokeping/
[root@smokeping smokeping]# ls
[root@smokeping smokeping]# cp -a htdocs/smokeping.cgi.dist htdocs/smokeping.cgi
[root@smokeping smokeping]# cp -a etc/config.dist etc/config
接着建立三个目录用于保存smokeping的数据等,如下所示:
[root@smokeping ~]# mkdir /usr/local/smokeping/data
[root@smokeping ~]# mkdir /usr/local/smokeping/var
[root@smokeping ~]# mkdir /usr/local/smokeping/cache
[root@smokeping ~]# chown -R apache.apache /usr/local/smokeping
mailhost = my.mail.host
sendmail = /usr/lib/sendmail
imgcache = /usr/local/smokeping/cache
cgiurl = http://192.168.101.81/smokeping/smokeping.cgismokemail = /usr/local/smokeping/etc/smokemail.dist
tmail = /usr/local/smokeping/etc/tmail.dist
*** Presentation ***
template = /usr/local/smokeping/etc/basepage.html.dist
binary = /usr/sbin/fping##修改为实际路径
binary = /usr/local/sbin/fping
把#*** Slaves ***下的所有东西注释掉,这里暂时不采用master/slave模式。
在Targets下添加监控节点,其中Multi也就是在一张图里画多个监测点的数值:
title = 21ViaNet(China)Telecom
menu = xjzhujunjie
title = xjzhujunjie-server
host = 192.168.101.82
title = JiLin_219.149.194.1
host = 219.149.194.1
title = 21ViaNet(China) Telecom Network
host = /Telecom/HeiLJ /Telecom/JiLin
[root@smokeping ~]# vim /usr/local/smokeping/htdocs/smokeping.cgi
use lib qw(/usr/local/rrdtool/lib/perl);
use lib qw(/usr/local/smokeping/lib);
use lib qw(/usr/local/rrdtool/lib/perl);
use lib qw(/usr/local/smokeping/lib);
[root@smokeping ~]# 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 <<EOF 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 |
[root@smokeping ~]# chmod +x /etc/init.d/smokeping
[root@smokeping ~]# ll /etc/init.d/smokeping
-rwxr-xr-x 1 root root 2109 Jun 16 16:52 /etc/init.d/smokeping
[root@smokeping ~]# /usr/local/smokeping/bin/smokeping --check
Configuration file '/usr/local/smokeping/etc/config' syntax OK.
ERROR: slave 'boomer' is not defined in the '*** Slaves ***' section!
/etc/init.d/smokeping start: smokeping could not be started
出现错误à将在后面解决…
[root@smokeping ~]# vim /etc/httpd/conf/httpd.conf
Alias /smokeping/ "/usr/local/smokeping/htdocs/"
Alias /cache/ "/usr/local/smokeping/cache/"
<Directory "/usr/local/smokeping/htdocs">
Options FollowSymLinks ExecCGI
AllowOverride None
AddHandler cgi-script cgi
[root@smokeping ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for smokeping.junjie.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@smokeping ~]#
出现错误à将在后面解决…
[root@smokeping ~]# vim /usr/local/smokeping/etc/config
binary = /usr/local/sbin/fping
sourceaddress = 0.0.0.0
Probes.FPing.binary = /usr/local/sbin/fping
Probes.FPing.sourceaddress = 192.168.101.82
[root@smokeping ~]# service smokeping restart
ERROR: /usr/local/smokeping/etc/config, line 111: File '/usr/local/smokeping/etc/smokeping_secrets.dist' is world-readable or writable, refusing it
/etc/init.d/smokeping start: smokeping could not be started
[root@smokeping src]# ll /usr/local/smokeping/etc/smokeping_secrets.dist
-rw-r--r-- 1 apache apache 59 Aug 21 2007 /usr/local/smokeping/etc/smokeping_secrets.dist
[root@smokeping src]# chmod 400 /usr/local/smokeping/etc/smokeping_secrets.dist
[root@smokeping src]# ll /usr/local/smokeping/etc/smokeping_secrets.dist
-r-------- 1 apache apache 59 Aug 21 2007 /usr/local/smokeping/etc/smokeping_secrets.dist
[root@smokeping src]#
[root@smokeping ~]# service smokeping restart
WARNING: Hostname 'james.address' does currently not resolve to an IPv6 or IPv4 address
ERROR: slave 'boomer' is not defined in the '*** Slaves ***' section!
/etc/init.d/smokeping start: smokeping could not be started
Probes.FPing.binary = /usr/local/sbin/fping
Probes.FPing.sourceaddress = 192.168.101.82
[root@smokeping ~]# service smokeping restart
/etc/init.d/smokeping start: smokeping started
[root@smokeping ~]#
[root@smokeping ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for smokeping.junjie.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
出现错误à成功解决
[root@smokeping ~]# vim /usr/local/smokeping/etc/config
menu = xjzhujunjie
title = xjzhujunjie-server
################web server###############
title = xjzhujunjie 网站 192.168.101.82
host = 192.168.101.82
[root@smokeping ~]# service smokeping stop
/etc/init.d/smokeping: line 14: gt: command not found
/etc/init.d/smokeping: line 14: /dev/null: Permission denied
/etc/init.d/smokeping stop: smokeping not running
[root@smokeping ~]# service smokeping start
WARNING: Hostname 'james.address' does currently not resolve to an IPv6 or IPv4 address
/etc/init.d/smokeping start: smokeping started
[root@smokeping ~]# vim /usr/local/smokeping/etc/config
to = xjzhujunjie@junjie.com
from = xjzhujunjie@junjie.com
pattern = >0%,*30*,>0%,*30*,>0% # in percent
comment = loss 1 packages in 30 continuous 3 times.
pattern = >15%,*30*,>15%,*30*,>15% # in percent
comment = loss 5 packages in 30 continuous 3 times.
pattern = ==S,>50,>50 # in milliseconds
comment = For more than two consecutive 50-millisecond delay.
[root@smokeping ~]# service smokeping stop
/etc/init.d/smokeping: line 14: gt: command not found
/etc/init.d/smokeping: line 14: /dev/null: Permission denied
/etc/init.d/smokeping stop: smokeping not running
[root@smokeping ~]# service smokeping start
WARNING: Hostname 'james.address' does currently not resolve to an IPv6 or IPv4 address
/etc/init.d/smokeping start: smokeping started
(1)to 表示接受所有报警的邮箱,如果需要在特定的节点报警发送到特定的邮箱则在该节点上增加alertee = xjzhujunjie@junjie.com 即可。
(2)manyloss 表示30个包丢15%的情况 连续出现3次就发报警。
(3)someloss 表示30个包丢1个,连续出现3次就发送报警;rttbad表示连续两个包延迟超过50ms就发送报警。
其它关于smokeping的使用,待续…….
《完》
Smokeiping 相关文档下载:http://down.51cto.com/data/432197