重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
smokeping是rrdtool的作者Tobi Oetiker的作品,用Perl语言写的,主要是监视网络性能,所以它在图形显示方面有很大优势,也是一个很有特点的opensource工具:多种探测方式,包括fping、echoping、dig、curl等;监视dns、ssh性能,底层也是rrdtool做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示,非常直观。同时也可以在多个节点收集同一个监测点的数据;很有特色的alert设置,不只是简单的设置一个阀值。
创新互联是一家集网站建设,紫金企业网站建设,紫金品牌网站建设,网站定制,紫金网站建设报价,网络营销,网络优化,紫金网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。主要有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 -y install freetypefreetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel perl perl-Net-Telnet perl-Net-DNSperl-LDAP * yum -y install perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6perl-CGI-SpeedyCGI rrdtool-perl * yum install perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-Radiu libxml2-devel libpng-devel pango pango-devel httpd-devel glib * yum -y install gcc gcc-c++ 2、安装rrdtool(绘图) * wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz * tar zxf rrdtool-1.4.7.tar.gz -C /usr/src/ && cd /usr/src/rrdtool-1.4.7 * ./configure --prefix=/usr/local/rrdtool * make && make install (报错:Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contain ..........) * yum -y install perl-ExtUtils-MakeMaker 即可解决 3、安装cgilib * wget http://down1.chinaunix.net/distfiles/cgilib-0.5.tar.gz * tar zxf cgilib-0.5.tar.gz -C /usr/src/ && cd /usr/src/cgilib-0.5 && make && cp libcgi.a /usr/local/lib && cp cgi.h /usr/include/ 4、安装fping * wget http://fping.sourceforge.net/download/fping.tar.gz * tar zxf fping.tar.gz -C /usr/src/ && cd /usr/src/fping.XX * ./configure && make && make install 5、安装echoping * wget http://jaist.dl.sourceforge.net/project/echoping/echoping/6.0.0/echoping-6.0.0.tar.gz * tar zxf echoping-6.0.0.tar.gz -C /usr/src/ && cd /usr/src/echoping-XXX * ./configure --without-libidn && make && make install * 会有报错:configure: error: Missing popt library * 解决:yum -y install popt-devel 即可 6、安装FCGI * wget http://cpan.communilink.net/authors/id/F/FL/FLORA/FCGI-0.74.tar.gz * tar zxf FCGI-0.74.tar.gz -C /usr/src/ && cd /usr/src/FCGI-XXX * perl Makefile.PL && make && make install 7、安装mod_fastcgi * wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz * tar zxf mod_fastcgi-2.4.6.tar.gz -C /usr/src/ && cd /usr/src/mod_fastcgi.XXX * apxs -o mod_fastcgi.so -c *.c && apxs -i -a -n fastcgi .libs/mod_fastcgi.so 8、安装Smokeping (注:会有问题,请看下面解决方案) * wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz * tar zxf smokeping-2.6.8.tar.gz -C /usr/src/ && cd /usr/src/smokeping-XXX * ./configure --prefix=/usr/local/smokeping * (报错:FCGI failed,CGI::Fast failed,config::Grammar failed ........) * ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty (时间有些长,安装完即可) * ./configure --prefix=/usr/local/smokeping * /usr/bin/gmake install
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…
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/”AllowOverride None Options ExecCGI AddHandler cgi-script .fcgi .cgi Order allow,deny Allow from all DirectoryIndex smokeping.fcgi
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 #this is a alerts script #v1.0 date=`date +%Y%m%d-%R` mail_log=“/usr/local/smokeping/var/alertmail_log_$date” mail_name=“xxx” echo “=====================$date=========================” > $mail_log echo $1 $mail_log #myloss(name) echo $2 $mail_log #Ustack.China_Netcom.ShenYang [from LG] echo $3 $mail_log #loss: 100%, 100%, 100%, 100% echo $4 $mail_log #rtt: U, U, U, U, U, U, U echo $5 $mail_log #202.96.75.68 loss=$3 avg=`echo $loss |tr -d 'a-z:,%' | sed 's/^\s*g' |awk -F' ' '{for (i=1;iNF;++i){sum+=$i;} print “agv:” su m / NF “%”}'` echo $avg $mail_log title=`echo $2|sed 's/ g'` echo $title $mail_log if [ -s $mail_log ];then # -n /usr/bin/python /home/chenjiayun/Myalerts.py $1 [SmokepingAlerts]$title $title $avg $5 fi #########################python mail api########################### #!/usr/bin/env python #this is a alerts script import sys import requests import json to = “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 = 3 if name == “someloss”: alert_priority=3 elif name == “rttdetect” or title == “rttdetect2”: alert_priority=2 elif name == “myloss2” or title == “myloss”: alert_priority=1 #all = subject+“\n”+loss+“\n”+rtt+“\n”+addr all = “%s Average loss: %s Ip is: %s ” %(title,loss,addr) content = { "alert_title": title, "alert_tag": "smokeping_server", "alert_priority": alert_priority, "alert_content": all, "alert_group": to } if name == “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 # Start the service Smokeping start() { echo -n “Starting Smokeping: ” /usr/local/smokeping/bin/smokeping –logfile=/var/log/smokeping.log >/dev/null 2>&1 ### Create the lock file ### touch /var/lock/subsys/smokeping success $“Smokeping startup” echo } # Restart the service Smokeping stop() { echo -n “Stopping Smokeping: ” kill -9 `ps ax | grep “/usr/local/smokeping/bin/smokeping” | grep -v grep | awk '{ print $1 }'` >/dev/null 2>&1 ### Now, delete the lock file ### rm -f /var/lock/subsys/smokeping success $“Smokeping shutdown” echo } ### main logic ### case “$1” in start) start ;; stop) stop ;; status) status Smokeping ;; restart|reload|condrestart) stop start ;; *) echo $“Usage: $0 {start|stop|restart|reload|status}” exit 1 esac exit 0
#!/bin/bash # smokeping reboot file # chenjiayun . /etc/init.d/functions # Start the service Smokeping start() { echo -n “Starting Smokeping: ” /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/null 2>&1 ### Create the lock file ### touch /var/lock/subsys/smokeping success $“Smokeping startup” echo } # Restart the service Smokeping stop() { echo -n “Stopping Smokeping: ” kill -9 `ps ax | grep “/usr/local/smokeping/bin/smokeping” | grep -v grep | awk ' { print $1 }'` >/dev/null 2>&1 ### Now, delete the lock file ### rm -f /var/lock/subsys/smokeping success $“Smokeping shutdown” echo } ### main logic ### case “$1” in start) start ;; stop) stop ;; status) status Smokeping ;; restart|reload|condrestart) stop start ;; *) echo $“Usage: $0 {start|stop|restart|reload|status}” exit 1 esac exit 0
效果图如下:
图2:
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。