Smokeping 监控搭建
smokeping是rrdtool的作者Tobi Oetiker的作品,用Perl语言写的,主要是监视网络性能,所以它在图形显示方面有很大优势,也是一个很有特点的opensource工具:多种探测方式,包括fping、echoping、dig、curl等;监视dns、ssh性能,底层也是rrdtool做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示,非常直观。同时也可以在多个节点收集同一个监测点的数据;很有特色的alert设置,不只是简单的设置一个阀值。
smokeping架构组件主要有Rrdtool 、Fping 、 Echoping 、 Curl 、 Dig 、 SSH 、 Perl 模块、SpeedyCGI 、 Apache等
在使用smokeping功能时,从单个节点去探测网络性能是有缺陷的,smokeping提供了多个节点的分布式部署功能,可以从多个节点去探测某个地区网络回调并显示至主服务器,也就是smokeping的主从模式
可视化的网络品质延迟。
交互式的图形浏览。
较多的网络测量插件。
主/从系统分布式测量。
高度可配置的警报系统。
直观的网络延迟图表。
自定义时间刷新图形显示。
缺点:
依赖包、组件过多,安装搭建配置较为繁琐。
图形参数较多,需要查阅相关文档
警报alerts接口可以调用外部程序,可传送5个相关参数:
警报名称 #eg:myloss
地址别名 #eg:Ustack.Publoc-google
loss规则 #eg:loss: S, 30%, 40%, 30%, 40%
延迟 #eg:rtt: S, 204ms, 200ms, 200ms, 200ms
ip地址 #eg:8.8.8.8
警报触发规则可参考官网说明http://oss.oetiker.ch/smokeping/doc/smokeping_config.en.html
RTT(Round-Trip Time)
普通列表项目它是一个数据报在网络上两点中间往返一次的时间。是影响TCP性能和表征网络运行状况的重要参数。在网络中实时、准确地测量大量TCP设备和系统的RTT参数是网络管的重要环节之一。Smokeping就是这样的自动测试系统,它向目标设备和系统发送各种类型的测试数据包,测量、记录和展示RTT
Median RTT 中间数
普通列表项目它是中间数并不是平均值。Smokeping有多种类型的探针,探针在默认的设置下,每300秒向目标设备发送20测探测数据包。假如这20个数据包都返回的话,它就记录下了20个RTT,那么Median RTT就是第十个包的RTT;如果有5个包丢失的话,那么Median RTT就是第八个返回的包的RTT值
Avg RTT 评价值
普通列表项目它是每一个测试回合中所有RTT的算术评价值
Avg pkt loss
它表示丢包率
Probe:10 ICMP Echo Pings(56 Bytes)every 30s
表示:每一个绿色的短横线都是一个测试回合30秒内用ping测试10次。绿色画出的是中间数的位置,一个回合中的其它值都在它附近被以灰度的形式被刻画
1、yum安装需要的软件包(若无法安装部分软件包,推荐用epel源)*yum-yinstallfreetypefreetype-develfontconfigcairocairo-devellibart_lgpllibart_lgpl-develperlperl-Net-Telnetperl-Net-DNSperl-LDAP*yum-yinstallperl-libwww-perlperl-RadiusPerlperl-IO-Socket-SSLperl-Socket6perl-CGI-SpeedyCGIrrdtool-perl*yuminstallperlperl-Net-Telnetperl-Net-DNSperl-LDAPperl-libwww-perlperl-Radiulibxml2-devellibpng-develpangopango-develhttpd-develglib*yum-yinstallgccgcc-c++2、安装rrdtool(绘图)*wgethttp://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz*tarzxfrrdtool-1.4.7.tar.gz-C/usr/src/&&cd/usr/src/rrdtool-1.4.7*./configure--prefix=/usr/local/rrdtool*make&&makeinstall(报错:Can'tlocateExtUtils/MakeMaker.pmin@INC(@INCcontain..........)*yum-yinstallperl-ExtUtils-MakeMaker即可解决3、安装cgilib*wgethttp://down1.chinaunix.net/distfiles/cgilib-0.5.tar.gz*tarzxfcgilib-0.5.tar.gz-C/usr/src/&&cd/usr/src/cgilib-0.5&&make&&cplibcgi.a/usr/local/lib&&cpcgi.h/usr/include/4、安装fping*wgethttp://fping.sourceforge.net/download/fping.tar.gz*tarzxffping.tar.gz-C/usr/src/&&cd/usr/src/fping.XX*./configure&&make&&makeinstall5、安装echoping*wgethttp://jaist.dl.sourceforge.net/project/echoping/echoping/6.0.0/echoping-6.0.0.tar.gz*tarzxfechoping-6.0.0.tar.gz-C/usr/src/&&cd/usr/src/echoping-XXX*./configure--without-libidn&&make&&makeinstall*会有报错:configure:error:Missingpoptlibrary*解决:yum-yinstallpopt-devel即可6、安装FCGI*wgethttp://cpan.communilink.net/authors/id/F/FL/FLORA/FCGI-0.74.tar.gz*tarzxfFCGI-0.74.tar.gz-C/usr/src/&&cd/usr/src/FCGI-XXX*perlMakefile.PL&&make&&makeinstall7、安装mod_fastcgi*wgethttp://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz*tarzxfmod_fastcgi-2.4.6.tar.gz-C/usr/src/&&cd/usr/src/mod_fastcgi.XXX*apxs-omod_fastcgi.so-c*.c&&apxs-i-a-nfastcgi.libs/mod_fastcgi.so8、安装Smokeping(注:会有问题,请看下面解决方案)*wgethttp://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz*tarzxfsmokeping-2.6.8.tar.gz-C/usr/src/&&cd/usr/src/smokeping-XXX*./configure--prefix=/usr/local/smokeping*(报错:FCGIfailed,CGI::Fastfailed,config::Grammarfailed........)*./setup/build-perl-modules.sh/usr/local/smokeping/thirdparty(时间有些长,安装完即可)*./configure--prefix=/usr/local/smokeping*/usr/bin/gmakeinstall
cd /usr/local/smokeping/
mkdir cache data var
chown –R apache.apache cache data var
cd /usr/local/smokeping/htdocs/
cp smokeping.fcgi.dist smokeping.fcgi
cd /usr/local/smokeping/etc/
cp config.dist config
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
chown apache.root /usr/local/smokeping/etc/smokeping_secrets.dist #slave 需要用到次文件,权限需分明
ln -s /usr/local/smokeping/cache /usr/local/smokeping/htdocs/cache
vim /usr/local/smokeping/etc/config
找到binary = /usr/sbin/fping ——— binary = /usr/local/sbin/fping
vi /usr/local/smokeping/bin/smokeping
找到:use lib qw(); ———— use lib qw(/usr/local/rrdtool/lib/perl);
* Alerts*
#to = XXX
to = |/home/chenjiayun/alerts.sh # 调用外部脚本 (传参上面已介绍,脚本见文章末尾)
from = XXX
+someloss
type = loss
pattern = >0%,*12*,>0%,*12*,>0% #loss的rule
comment = loss 3 times in a row
+myloss
type = loss
pattern = >50%,*10*,>50%,*10*,>50% #loss的rule
comment = loss 4 packages in 10 continuous 3times.
* Slaves*
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+LG # slave 主机
display_name=LG
color=7fff00
+ZHSH #slave 主机 可以有多个
display_name=ZHSH
color=9400d3
* Targets*
remark = Welcome to the SmokePing website of Unitedstack Company. Here you will learn all about the latency of our network.
slaves = LG ZHSH #添加slave
+ Ustack
menu= Network Stastic
title= All Links
++ China_Netcom
menu = China Unicom
title = China Unicom Status
+++ Beijing
menu = (UNI)Beijing
title =Beijing-DNS
alerts = myloss,myloss2 #添加规则,可触发警报
host = 210.73.64.1
等等
##################全国网络绘图###################
+ National_Network
menu = National Overview
title = National Overview
host = /Ustack/China_Netcom/Beijing /Ustack/China_Netcom/Shanghai /Ustack/China_Netcom/GuangZhou /Ustack/China_Netcom/ChengDu…..
+ National_Network1
menu = National Overview(LG)
title = National Overview(LG)
host = /Ustack/China_Netcom/Beijing~LG /Ustack/China_Netcom/Shanghai~LG /Ustack/China_Netcom/GuangZhou~LG /Ustack/China_Netcom/ChengDu~LG…
Apache的配置vim/etc/httpd/conf/httpd.cof添加Alias/smokeping“/usr/local/smokeping/htdocs/smokeping.fcgi”Alias/cache“/usr/local/smokeping/cache”Alias/cropper“/usr/local/smokeping/htdocs/cropper/”<Directory“/usr/local/smokeping/”>AllowOverrideNoneOptionsExecCGIAddHandlercgi-script.fcgi.cgiOrderallow,denyAllowfromallDirectoryIndexsmokeping.fcgi</Directory>
slave搭建与master一致
slave不需要配置
唯一需要配置的是 smokeping_secrets.dist文件(保存的是密码,主服务器上保存的是用户名及密码,密码与之对应,客户端启动需要用户名)
启动: 若启动出错,可以–debug-daemon –logfile=file.txt 分析
客户端启动需要连接master的URL,确保公网可以访问
Apache启动
service httpd restart
smokeping master 启动
/usr/local/smokeping/bin/smokeping –logfile=/var/log/smokeping.log >/dev/null 2>&1 (–debug-daemon)
smokeping slave 启动
/usr/local/smokeping/bin/smokeping –master-url=http://ping.monitor.ustack.com–cache-dir=/usr/local/smokeping/cache –shared-secret=/usr/local/smokeping/etc/smokeping_secrets.dist –slave-name=LG –logfile=/var/log/smokeping.log >/dev/null 2>&1
注:–slave-name 在master的smokeping_secrets.dist中存在密码,与客户端smokeping_secrets.dist密码一致
报警邮件脚本
#!/bin/bash#thisisaalertsscript#v1.0date=`date+%Y%m%d-%R`mail_log=“/usr/local/smokeping/var/alertmail_log_$date”mail_name=“xxx”echo“=====================$date=========================”>$mail_logecho$1$mail_log#myloss(name)echo$2$mail_log#Ustack.China_Netcom.ShenYang[fromLG]echo$3$mail_log#loss:100%,100%,100%,100%echo$4$mail_log#rtt:U,U,U,U,U,U,Uecho$5$mail_log#202.96.75.68loss=$3avg=`echo$loss|tr-d'a-z:,%'|sed's/^\s*g'|awk-F'''{for(i=1;iNF;++i){sum+=$i;}print“agv:”sum/NF“%”}'`echo$avg$mail_logtitle=`echo$2|sed's/g'`echo$title$mail_logif[-s$mail_log];then#-n/usr/bin/python/home/chenjiayun/Myalerts.py$1[SmokepingAlerts]$title$title$avg$5fi#########################pythonmailapi############################!/usr/bin/envpython#thisisaalertsscriptimportsysimportrequestsimportjsonto=“devops”name=sys.argv[1]title=sys.argv[2]subject=“City_name:”+sys.argv[3]loss=sys.argv[4]addr=sys.argv[5]alert_priority=3ifname==“someloss”:alert_priority=3elifname==“rttdetect”ortitle==“rttdetect2”:alert_priority=2elifname==“myloss2”ortitle==“myloss”:alert_priority=1#all=subject+“\n”+loss+“\n”+rtt+“\n”+addrall=“%sAverageloss:%sIpis:%s”%(title,loss,addr)content={"alert_title":title,"alert_tag":"smokeping_server","alert_priority":alert_priority,"alert_content":all,"alert_group":to}ifname==“main”:url='http://alerting.ustack.com:8080/v1/alerts'headers={'content-type':'application/json'}r=requests.post(url,data=json.dumps(content),headers=headers)
#!/bin/bash#jiayun./etc/init.d/functions#StarttheserviceSmokepingstart(){echo-n“StartingSmokeping:”/usr/local/smokeping/bin/smokeping–logfile=/var/log/smokeping.log>/dev/null2>&1###Createthelockfile###touch/var/lock/subsys/smokepingsuccess$“Smokepingstartup”echo}#RestarttheserviceSmokepingstop(){echo-n“StoppingSmokeping:”kill-9`psax|grep“/usr/local/smokeping/bin/smokeping”|grep-vgrep|awk'{print$1}'`>/dev/null2>&1###Now,deletethelockfile###rm-f/var/lock/subsys/smokepingsuccess$“Smokepingshutdown”echo}###mainlogic###case“$1”instart)start;;stop)stop;;status)statusSmokeping;;restart|reload|condrestart)stopstart;;*)echo$“Usage:$0{start|stop|restart|reload|status}”exit1esacexit0Slave 服务启动代码
#!/bin/bash#smokepingrebootfile#chenjiayun./etc/init.d/functions#StarttheserviceSmokepingstart(){echo-n“StartingSmokeping:”/usr/local/smokeping/bin/smokeping–master-url=http://ping.monitor.ustack.com–cache-dir=/usr/local/smokeping/cache–shared-secret=/usr/local/smokeping/etc/smokeping_secrets.dist–slave-name=ZHSH–logfile=/var/log/smokeping.log>/dev/null2>&1###Createthelockfile###touch/var/lock/subsys/smokepingsuccess$“Smokepingstartup”echo}#RestarttheserviceSmokepingstop(){echo-n“StoppingSmokeping:”kill-9`psax|grep“/usr/local/smokeping/bin/smokeping”|grep-vgrep|awk'{print$1}'`>/dev/null2>&1###Now,deletethelockfile###rm-f/var/lock/subsys/smokepingsuccess$“Smokepingshutdown”echo}###mainlogic###case“$1”instart)start;;stop)stop;;status)statusSmokeping;;restart|reload|condrestart)stopstart;;*)echo$“Usage:$0{start|stop|restart|reload|status}”exit1esacexit0
效果图如下:
图2:
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。