linux下構建Smokeping網絡監控平臺html
一. Smokeping 簡介linux
1.1 Smokeping簡介:git
Smokeping 是rrdtool 的做者Tobi Oetiker 的做品,是用Perl 寫的,主要是監視網絡性能,包括常規的ping,用echoping監控www 服務器性能,監視dns 查詢性能,監視ssh 性能等。底層也是rrdtool作支持,特色是畫的圖很是漂亮,網絡丟包和延遲用顏色和陰影來表示。web
1.2 Smokeping 架構組件數據庫
Smokeping 有如下組件組成:RRDtool、Fping、Echoping、Curl、Dig、SSh、Perl 模塊,Perl、SpeedyCGI、Apache 等。apache
master/slave 的工做方式,能夠在多個節點收集同一個監測點的數據;vim
1.3 Smokeping 相關資源瀏覽器
2> Smokeiping 相關文檔下載:http://down.51cto.com/data/432197bash
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
[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