您好,登錄后才能下訂單哦!
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/” <Directory “/usr/local/smokeping/”> AllowOverride None Options ExecCGI AddHandler cgi-script .fcgi .cgi Order allow,deny Allow from all DirectoryIndex smokeping.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 #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:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。