Smokeping搭建優化【原創】

 

 

 

 

 

1 什麼是smokeping

2 smokeping架構組成

3 smokeping分佈式介紹

4 如何看懂smokeping圖表

5 如何判斷一個節點的好壞

Smokepingrrdtool的作者TobiOetiker 的作品,是用Perl 寫的,主要是監視網絡性能,包括常規的ping,用echoping www 服務器性能,監視dns 查詢性能,監視ssh 性能等。底層也是rrdtool做支持,特點是畫的圖非常亮,網絡丟包和延遲用顏色和陰影來表示。

Smokeping由以下組件組成:

RRDtoolFpingEchopingCurlDigSShPerl 模塊,

PerlSpeedyCGIApacheORNGINX

使用Smokeping的過程中,很容易就發現,如果從單個節點去探測網絡性能,往往是不夠的,Smokeping提供了多節點的分佈式部署功能,也就是可以從多個節點去探測到某個地區的網絡狀態,這樣纔是我們監控網絡希望看到的情況。

Smokeping稱其爲主從模式,主從模式的配置很簡單,從服務器的安裝和主服務器相同,只是從服務器不用自己的config文件,而是在啓動的過程中請求主服務器的config文件,這樣你只需要維護主服務器上的配置文件即可。

Smokeping檢測分佈式的檢測方式是被動模式,由從節點啓動時獲得主節點的config文件,然後進行測試,測試完畢後直接將數據提交給主節點。主從通信驗證是通過我們可以設置多個從服務器,主從服務器通過指定--shared-secret=filename來和主進行密碼驗證。

 

X軸表示時間軸

Y軸表示ping的時間值

3.6ms表示 Ping質量測試的響應速度平均值

中間紅線能看出網絡是否有抖動

直線表示穩定,有頻繁曲線表示網絡抖動;如果是陰影表示有網絡小幅度抖動

ls字段表示Ping質量測試的丟包率


根據網絡抖動判斷,抖動範圍超過10ms的都屬於網絡不穩定我們要每天觀察是否都有規律的網絡抖動現象

 

根據丟包狀況判斷:

剛進入詳細報告後,看總曲線的顏色,根據20個測試數據包返回的數據判斷

綠色表示0丟包.屬於最好.淺藍色1個丟包,深藍色2個丟包….以此類推

從這個報告圖裏可以看出:

1.曲線都是綠色的0丟包或偶爾一兩個丟包算合格

2.曲線無抖動,陰影不明顯或偶爾有抖動的算合格(包裹陰影部分)

3.Ping值小於30ms如果小於50ms還算合格



smokeping搭建

1服務端安裝

可分多種web框架可選nginx apache等 接口可選fsgi cgi 

1)apache安裝略  
httpd.conf中directory字段加入
</Directory>
<Directory "/usr/local/smokeping/htdocs">
#Options FollowSymLinks ExecCGI
Options Indexes FollowSymLinks
Options ExecCGI
#AllowOverride None
#Order allow,deny
#Allow from all
</Directory>

Alias /smokeping "/usr/local/smokeping/"
<Directory /usr/local/smokeping/>
        AllowOverride None
        AddHandler cgi-script cgi
        Options ExecCGI
        Options Indexes FollowSymLinks
        Order allow,deny
        Allow from all
        DirectoryIndex smokeping.cgi
</Directory>

 

 1).rrdtool.FPing.EchoPing.Curl.dig.SSH
      wget http://sourceforge.net/projects/echoping/files/echoping/6.0.2/echoping-6.0.2.tar.gz/download
      wget http://fping.sourceforge.net/download/fping.tar.gz
      wget http://dag.wieers.com/rpm/packages/echoping/echoping-5.2.0-1.2.el5.rf.x86_64.rpm
      wget http://dag.wieers.com/rpm/packages/fping/fping-2.4-1.b2.2.el5.rf.x86_64.rpm
      rpm -ivh *ping*x86_64.rpm
      yum install -y freetype freetype-devel libpng libpng-devel gd gd-devel pango pango-devel libxml2 libxml2-devel libart_lgpl libart_lgpl-devel perl-libwww-perl perl-IO-Socket-SSL perl-Net-Telnet perl-Socket6 perl-Net-DNS perl-LDAP      
      wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.5.tar.gz
      tar zvxf rrdtool-1.4.5.tar.gz && cd rrdtool-1.4.5
      sed -i 's/setlocale(LC_NUMERIC, "C")/setlocale(LC_NUMERIC, "zh_CN.UTF-8")/g' src/rrd_graph.c
      ./configure --prefix=/usr/local/rrdtool --enable-perl-site-install --with-perl-options &&make &&make install
      perl -MRRDs -le 'print q(ok!)'  查看RRDs.pm  提示加載libdbi.so.o加載不上,安裝yum install libdbi
   2).perl(Perl 5.8.8)的模塊支持
      #perl -MCPAN -e -shell
      #install FCGI,CGI,CGI::Fast,Config::Grammar,Digest::HMAC_MD5,Net::Telnet,Net::OpenSSH,Net::SNMP,Net::LDAP,Net::DNS, IO::Pty,LWP,Socket6,IO::Socket::SSL
      perl -MCPAN -e 'install FCGI,CGI,CGI::Fast,Config::Grammar,Digest::HMAC_MD5,Net::Telnet,Net::OpenSSH,Net::SNMP,Net::LDAP,Net::DNS, IO::Pty,LWP,Socket6,IO::Socket::SSL'
   3).smokeping安裝
     export PERL5LIB=/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/  #64位系統
     export PERL5LIB=/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/  #32位系統
     wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.6.tar.gz
     tar zvxf smokeping-2.6.6.tar.gz && cd smokeping-2.6.6
     ./configure --prefix=/usr/local/smokeping &&make &&make install

 

########################分割線###############################################

smokeping config中需要配置的項和優化

*** General ***

owner    = www.funshion.com
contact  = [email protected]
mailhost = mail.funshion.com
sendmail = /usr/sbin/sendmail
# NOTE: do not put the Image Cache below cgi-bin
# since all files under cgi-bin will be executed ... this is not
# good for images.
imgcache = /usr/local/smokeping/cache
imgurl   = http://192.168.x.x/smokeping/cache
datadir  = /usr/local/smokeping/data
piddir  = /usr/local/smokeping/var
cgiurl   = http://192.168.x.x/smokeping/htdocs/smokeping.cgi
smokemail = /usr/local/smokeping/etc/smokemail
tmail = /usr/local/smokeping/etc/tmail
# specify this to get syslog logging
syslogfacility = local0
# each probe is now run in its own process
# disable this to revert to the old behaviour
concurrentprobes = yes

*** Alerts ***
to = [email protected]
from = [email protected]

+someloss
type = loss
# in percent
pattern = >3%,*12*,>3%,*12*,>3%
comment = detected loss 3 times over the last two hours

+highloss
type = loss
# in percent
pattern = >50%,*12*,>50%,*12*,>50%
comment = detected loss 3 times over the last two hours

+rttdetect
type = rtt
# in milliseconds
pattern = <100,<100,<100,<100,<100,>100,>100,>100,>100
comment = routing messed up again ?

+highrttdetect
type = rtt
# in milliseconds
pattern = <20,<20,<20,<20,<20,>20,>20,>20,>20
comment = routing messed up again ?
*** Database ***

step     = 300
pings    = 100

# consfn mrhb steps total

AVERAGE  0.5   1  1008
AVERAGE  0.5  12  4320
    MIN  0.5  12  4320
    MAX  0.5  12  4320
AVERAGE  0.5 144   720
    MAX  0.5 144   720
    MIN  0.5 144   720

*** Presentation ***

template = /usr/local/smokeping/etc/basepage.html
charset = utf-8

+ charts

menu = Charts
title = The most interesting destinations

++ stddev
sorter = StdDev(entries=>4)
title = Top Standard Deviation
menu = Std Deviation
format = Standard Deviation %f

++ max
sorter = Max(entries=>5)
title = Top Max Roundtrip Time
menu = by Max
format = Max Roundtrip Time %f seconds

++ loss
sorter = Loss(entries=>5)
title = Top Packet Loss
menu = Loss
format = Packets Lost %f

++ median
sorter = Median(entries=>5)
title = Top Median Roundtrip Time
menu = by Median
format = Median RTT %f seconds

+ overview 

width = 600
height = 100
range = 12h

+ detail

width = 600
height = 200
#loss_background = yes
unison_tolerance = 2

"最後1天"       1d
"最後1周"       7d
"最後1個月"     30d

++loss_colors
0    00ff00    "0"
1    00b8ff    "1/100"
2    0059ff    "2/100"
3    5e00ff    "3/100"
4    7e00ef    "4/100"
5    ffff00    "5/100"
10   ff00ff    "10/100"
50   ff0000    "50/100"
#99   ff0000    "99/100"

#+ hierarchies
#++ owner
#title = Host Owner
#++ location
#title = Location

*** Probes ***

+ FPing

binary = /usr/sbin/fping

*** Slaves ***
secrets=/usr/local/smokeping/etc/secrets

+zhengzhoucnc
display_name=鄭州聯通
color=b0e0e6

*** Targets ***
probe = FPing

menu = Top
title = www.funshion.com
remark = 歡迎使用smokeping監控
menuextra = <a target='_blank' href='tr.html{HOST}' class='{CLASS}'onclick="window.open(this.href,this.target, 'width=800,height=500,toolbar=no,location=no,status=no,scrollbars=no'); return false;">*</a>

+ CNC-OTHER-NODE
menu = 聯通NODE
title = 聯通NODE
nomasterpoll = yes


++ zhengzhou
menu = 鄭州聯通
title = 鄭州聯通
alerts = someloss,rttdetect
slaves = beijingcnc 
host = 182.118.x.x

+++ zhengzhou
menu = 鄭州聯通
title = 鄭州聯通
alerts = 
slaves = huhehaotecnc  shenyangcnc  taiyuancnc tianjincnc guangzhoucnc shijiazhuangcnc
host = 182.118.x.x

 


+ Test
menu = 測試
title = 測試
nomasterpoll = yes


++ TW
menu = 臺灣
title = 臺灣
alerts =
slaves = beijingcnc yizhuangctc-waiwang nanningctc nanchangctc
host = 60.199.217.26



1 此處定義節點由於較多所以只寫了一個鄭州

2 此配置文件針對監控優先級報警 採用了3層目錄形式 可針對自己想監控的節點進行報警,極大降   低了誤報

3 Alerts定義多種規則,針對不通網絡質量採用不通閥值 

當然smokeping也支持如RTX 飛信等報警 需要手工寫一些腳本或添加相應程序實現

 

 

1 smokeping.cgi 放置在 htdocs下

#!/bin/sh
#export PERL5LIB=/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/
exec /usr/local/smokeping/bin/smokeping_cgi /usr/local/smokeping/etc/config 

讓smokeping_cgi讀取配置文件執行

2 smokeping生成的cache圖片按照定義時間來定義 last_ 後面的數值

3 必須刷新url纔可生成cache圖片,可定期使用腳本刷新

4 secrets文件權限600

 

5 smokeping服務端啓動腳本

killall -9 smokeping
/usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --logfile=/usr/local/smokeping/htdocs/var/smokeping.log

6 smokeping客戶端啓動腳本

#!/bin/bash
MASTERURL=http://xxx.xx.xx.xx/htdocs/smokeping.cgi
SLAVENAME=
CACHEDIR=/usr/local/smokeping/cache
PIDFILE=$CACHEDIR/smokeping.pid
SECRET=/usr/local/smokeping/etc/secrets
LOGFILE=/usr/local/smokeping/var/smoke.log

RUNNING=0

if [ -f $PIDFILE ] ; then
    PID=`cat $PIDFILE`
    if kill -0 $PID 2>/dev/null ; then
        echo "smokeping is running with PID $PID"
        exit 0
    else
        echo "smokeping not running but PID file exists => delete PID file"
        rm -f $PIDFILE
    fi
else
    echo "smokeping (no pid file) not running"
fi

if
/usr/local/smokeping/bin/smokeping --master-url=$MASTERURL --slave-name=$SLAVENAME --cache-dir=$CACHEDIR --shared-secret=$SECRET --logfile=$LOGFILE > /dev/null; then
    echo "smokeping started"
else
echo "smokeping could not be started"
fi

 

 

 

歡迎大家交流或給我留言 







 

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