linux下構建Smokeping網絡監控平臺

 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 相關資源

1> Smokeping 官方網站:http://oss.oetiker.ch/smokeping/

2> Smokeiping 相關文檔下載:http://down.51cto.com/data/432197

3> Smokeiping 相關軟件下載地址:http://down.51cto.com/data/432183 

二.Smokeping 安裝 

2.1 準備工作

[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

[rhel-server]

name=Red Hat Enterprise Linux server

baseurl=file:///mnt/cdrom/Server/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-vt]

name=Red Hat Enterprise Linux vt

baseurl=file:///mnt/cdrom/VT/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-cluster]

name=Red Hat Enterprise Linux cluster

baseurl=file:///mnt/cdrom/Cluster/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-clusterstorage]

name=Red Hat Enterprise Linux clusterstorage

baseurl=file:///mnt/cdrom/ClusterStorage/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

[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

2.2 安裝rrdtool

RRDTool 是由Tobias Oetiker 開發的開源軟件,它使用RRD(Round Rebin Databases)作爲存儲格式,Round robin 是一種處理定量數據以及當前元素指針的技術,RRDTool 主要用來跟蹤對象的變化情況,生成改對象變化的趨勢圖。

[root@smokeping ~]# cd /root/smokeping/

[root@smokeping smokeping]# ls

cgilib-0.5.tar.gz

CGI-SpeedyCGI-2.22.tar.gz
echoping-6.0.2.tar.gz
fping.tar.gz
rrdtool-1.4.4.tar.gz
smokeping-2.4.2.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

LANG="zh_CN.UTF-8"

[root@smokeping smokeping]# export LANG="zh_CN.UTF-8"

[root@smokeping smokeping]# yum -y install fonts-chinese

安裝rrdtool

[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

執行rrdtool 命令,如果出現以下輸出,表示安裝成功,並列出了該命令的使用幫助。

[root@smokeping rrdtool-1.4.4]# cd /usr/local/rrdtool/bin/

[root@smokeping bin]# ll

total 400

-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 <[email protected]>

               Compiled Jun 17 2012 09:50:49
 

Usage: rrdtool [options] command command_options

Valid commands: create, update, updatev, graph, graphv,  dump, restore,

              last, lastupdate, first, info, fetch, tune,

              resize, xport, flushcached
 

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]#

2.3安裝FpingEchoping

[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]#tar -zxvf echoping-6.0.2.tar.gz -C /usr/local/src/

[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

 
2.4 安裝cgilibSpeedyCGI

[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/

[root@smokeping cgilib-0.5]# ls

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]#
[root@smokeping cgilib-0.5]# make

[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/

[root@smokeping CGI-SpeedyCGI-2.22]# ls

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

[root@smokeping CGI-SpeedyCGI-2.22]# make install

2.5 安裝Perl模塊
以下全是Smokeping 需要的perl 模塊。
[root@smokeping CGI-SpeedyCGI-2.22]# cd

[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

2.6 安裝Smokeping

[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

3.1修改smokeping相關文件名

在smokeping的子目錄中會發現很多“*.dist”命名的文件,這些文件使用的時候請將其改名爲“*”並進行配置

[root@smokeping ~]# cd /usr/local/smokeping/

[root@smokeping smokeping]# ls

[root@smokeping smokeping]# cp -a bin/smokeping.dist bin/smokeping

[root@smokeping smokeping]# cp -a htdocs/smokeping.cgi.dist htdocs/smokeping.cgi

[root@smokeping smokeping]# cp -a etc/config.dist etc/config

3.2建立相關目錄

接着建立三個目錄用於保存smokeping的數據等,如下所示:

[root@smokeping ~]# mkdir /usr/local/smokeping/data

[root@smokeping ~]# mkdir /usr/local/smokeping/var

[root@smokeping ~]# mkdir /usr/local/smokeping/cache

[root@smokeping ~]# yum install -y httpd

[root@smokeping ~]# chown -R apache.apache /usr/local/smokeping

3.3修改配置文件
1/usr/local/smokeping/etc/config somkeping配置基本都在這個文件上)
*** General ***
 
owner    = xjzhujunjie
contact  = [email protected]

mailhost = my.mail.host

sendmail = /usr/lib/sendmail

imgcache = /usr/local/smokeping/cache

imgurl   = cache
datadir  = /usr/local/smokeping/data
piddir  = /usr/local/smokeping/var

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

 
+ charts
+ FPing

binary = /usr/sbin/fping##修改爲實際路徑

binary = /usr/local/sbin/fping

把#*** Slaves ***下的所有東西註釋掉,這裏暫時不採用master/slave模式。

#*** Slaves ***
#secrets=/home/oetiker/checkouts/smokeping/trunk/software/etc/smokeping_secrets.dist
#+boomer
#display_name=boomer
#color=0000ff
 
#+slave2
#display_name=another
#color=00ff00

在Targets下添加監控節點,其中Multi也就是在一張圖裏畫多個監測點的數值:

+ Telecom
menu= TeleCom

title = 21ViaNet(China)Telecom

++ xjzhujunjie

menu = xjzhujunjie

title = xjzhujunjie-server

host = 192.168.101.82

++ JiLin
menu = JiLin

title = JiLin_219.149.194.1

host = 219.149.194.1

++ TeleComMulti
menu = TeleMulti

title = 21ViaNet(China) Telecom Network

host = /Telecom/HeiLJ /Telecom/JiLin

2/usr/local/smokeping/htdocs/smokeping.cgi注意修改如下內容即可

[root@smokeping ~]# vim /usr/local/smokeping/htdocs/smokeping.cgi

use lib qw(/usr/local/rrdtool/lib/perl);

use lib qw(/usr/local/smokeping/lib);

Smokeping::cgi("/usr/local/smokeping/etc/config");
3/usr/local/smokeping/bin/smokeping注意修改如下內容即可:

use lib qw(/usr/local/rrdtool/lib/perl);

use lib qw(/usr/local/smokeping/lib);

Smokeping::main("/usr/local/smokeping/etc/config");
3.4啓動smokeping
1)編寫smokeping啓動腳本: 賦予可執行權限,並放在/etc/init.d目錄下

[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&gt;/dev/null ; then

# smokeping is running

RUNNING=1
else

# smokeping not running but PID file exists =&gt; 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 &gt; /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 &gt; /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 &gt;/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 &gt;/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 <&lt;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

2)檢查smokeping配置文件:

[root@smokeping ~]# /usr/local/smokeping/bin/smokeping --check

Configuration file '/usr/local/smokeping/etc/config' syntax OK.

3)啓動smokeping:(無法啓動)
[root@smokeping ~]# service smokeping start

ERROR: slave 'boomer' is not defined in the '*** Slaves ***' section!

/etc/init.d/smokeping start: smokeping could not be started

 

出現錯誤à將在後面解決

 
4)配置apache  /conf/httpd.conf

[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

Order allow,deny
Allow from all
</Directory>

[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 ~]#

5)測試。修改完後重啓apache,在瀏覽器輸入http://192.168.101.81/smokeping/smokeping.cgi
 

失敗。。。待續。。。
3.5 錯誤排查與測試:

出現錯誤à將在後面解決

[root@smokeping ~]# vim /usr/local/smokeping/etc/config

+ FPing
 

binary = /usr/local/sbin/fping

sourceaddress = 0.0.0.0

*** Slaves ***
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+192.168.101.82
display_name=192.168.101.82
location=junjie
color=0000ff
++override

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

 
*** Slaves ***
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+boomer
display_name=boomer
location=junjie
color=00ffff
+192.168.101.82
display_name=192.168.101.82
location=junjie
color=0000ff
++override

Probes.FPing.binary = /usr/local/sbin/fping

Probes.FPing.sourceaddress = 192.168.101.82

 
+slave2
display_name=another
color=00ff00
 

[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  ]

出現錯誤à成功解決 

4.1 監控節點的增加

[root@smokeping ~]# vim /usr/local/smokeping/etc/config

+ xjzhujunjie

menu = xjzhujunjie

title = xjzhujunjie-server

################web server###############

++ junjie-web
menu = junjie-web

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

4.2 報警設置
smokeping的alert設置有點複雜,但是卻很好用,設置很靈活,考慮得很周全。它可以使用郵件進行alert,也可以直接調用外部程序進行IM的報警。在我們的監控中主要是採用郵件報警。報警參數設置如下,哪個節點需要報警增加alerts = manyloss即可

[root@smokeping ~]# vim /usr/local/smokeping/etc/config

*** Alerts ***

to = [email protected]

from = [email protected]

 
+someloss
type = loss

pattern = >0%,*30*,>0%,*30*,>0% # in percent

comment = loss 1 packages in 30 continuous 3 times.

+manyloss
type = loss

pattern = >15%,*30*,>15%,*30*,>15% # in percent

comment = loss 5 packages in 30 continuous 3 times.

+rttbad
type = rtt

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 = [email protected] 即可。

(2)manyloss 表示30個包丟15%的情況 連續出現3次就發報警。

(3)someloss 表示30個包丟1個,連續出現3次就發送報警;rttbad表示連續兩個包延遲超過50ms就發送報警。

4.3 畫圖設置
Smokeping默認設置中是每5分鐘畫一次圖,每5分鐘發送20個ping包。網絡工程師認爲5分鐘發送20個ping包太少,建議改爲5分鐘100個。畫圖的顏色等也要進行相應的更改: 在Database中,step =300 pings =20 改爲 step = 300 pings =100

從圖上可以看到,slave主機會自己去檢查監測點的情況(loss and rtt),並將數值提交給master主機(通過smokeping.cgi)。值得注意的是,slave並不需要config文件,每次slave提交完數據以後,會詢問master它自己的配置文件是否有修改,如果有修改的話slave會進行更新。

其它關於smokeping的使用,待續…….

《完》

--xjzhujunjie
--2012/06/16

Smokeiping 相關文檔下載:http://down.51cto.com/data/432197

Smokeiping 相關軟件包下載地址:http://down.51cto.com/data/432183 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章