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

三. 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  ]

出现错误à成功解决 

四. Smokeping 的其它配置
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 

你可能感兴趣的:(linux,运维,系统,监控,smokeping)