1. 程式人生 > >監控軟件之SmokePing

監控軟件之SmokePing

訪問 art video air htpasswd 51cto arch url pro

一、SmokePing簡介
Smokeping 是rrdtool 的作者Tobi Oetiker 的作品,是用Perl 寫的,主要是監視網絡性能,包括常規的ping,用echoping監控www 服務器性能,監視dns 查詢性能,監視ssh 性能等。底層也是rrdtool做支持,特點是畫的圖非常漂亮,網絡丟包和延遲用顏色和陰影來表示。在企業中運用較少。
二、系統設置
2.1系統設置
安裝wget下載工具
yum -y install wget
修改本地源,先備份現有的源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
切換到阿裏雲的源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安裝源數據緩存
yum makecache
系統升級
yum -y update
安裝"Compatibility libraries" "Base" "Development tools"這三個組套件
yum groupinstall "Compatibility libraries" "Base" "Development tools" -y
2.2、關閉SeLinux
修改/etc/selinux/config 文件
將SELINUX=enforcing改為SELINUX=disabled
2.3、關閉防火墻
systemctl stop firewalld.service
systemctl disable firewalld.service
2.4、設置NTP
ntpdate times.aliyun.com
三、SmokePing安裝
Smokeping 需要多個包的支持,下面我們逐個安裝,這裏通過yum和編譯安裝兩種方式。
yum install -y ntpdate perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-IO-Socket-SSL perl-Socket6 perl-Time-HiRes perl-ExtUtils-MakeMaker perl-Sys-Syslog rrdtool rrdtool-perl curl httpd httpd-devel gcc make wget libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel popt popt-devel libidn libidn-devel perl-core wqy-zenhei-fonts.noarch
下面這個三個安裝包無法通過yum安裝,需要通過wget工具下載本地編譯安裝
smokeping-2.6.8、fping 4.0、echoping 6.0.2
下載鏈接如下:
wget http://fping.org/dist/fping-4.0.tar.gz
wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz
wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz
根據個人愛好選擇下載目錄,下面以/tmp/smokeping/為下載目錄說明安裝
fping編譯安裝:
tar xf fping-4.0.tar.gz
cd fping-4.0
./configure
make && make install
echoping編譯安裝:
tar xf echoping-6.0.2.tar.gz
cd echoping-6.0.2
./configure
make && make install
smokeping 編譯安裝
tar xf smokeping-2.6.8.tar.gz
cd smokeping-2.6.8
#exportPERL5LIB=/usr/local/smokeping/thirdparty/lib/perl5/
安裝perl的模塊
./setup/build-perl-modules.sh /etc/smokeping/thirdparty
如果沒有安裝perl的模塊,直接安裝會出現下面的錯誤
-------------------------------------------------------------
Aborting Configure

If you know where perl can find the missing modules, set
the PERL5LIB environment variable accordingly.

FIRST though, make sure that ‘perl‘ starts the perl
binary you want to use for SmokePing.

Now you can install local copies of the missing modules
by running

./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty

The RRDs perl module is part of RRDtool. Either use the rrdtool
package provided by your OS or install rrdtool from source.
If you install from source, the RRDs module is located
PREFIX/lib/perl
-------------------------------------------------------------
./configure --prefix=/etc/smokeping
/usr/bin/gmake install
四、下面就是SmokePing的配置了
1、進入/etc/smokeping/目錄
cd /etc/smokeping/
2、新建目錄cache、data、var,日誌log,並修改宿主權限
mkdir cache data var
chown apache:apache cache data var
chown apache:apache /var/log/smokeping.log
touch /var/log/smokeping.log
chown apache:apache /var/log/smokeping.log
修改smokeping_secrets.dist權限
chmod 600 /etc/smokeping/etc/smokeping_secrets.dist
cd /etc/smokeping/htdocs
cp smokeping.fcgi.dist smokeping.fcgi
創建軟連接
ln -sd ../cache cache
cd /etc/smokeping/etc
cp config.dist config
修改配置文件
vi config
主要修改如下內容:
#cgiurl = http://some.url/smokeping.cgi
cgiurl = http://10.0.0.62/smokeping.cgi

Database
#step = 300
step = 60 #此處建議改為 60 , 一分鐘采集一次數據
pings = 20
修改apache配置
vi /etc/httpd/conf/httpd.conf
末尾添加如下:
# SmokePing
Alias /cache "/etc/smokeping/cache/"
Alias /cropper "/etc/smokeping/htdocs/cropper/"
Alias /smokeping "/etc/smokeping/htdocs/"
<Directory "/etc/smokeping/">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
DirectoryIndex smokeping.fcgi
Require all granted
</Directory>
如果需要支持中文,需要安裝中文編碼:
vim /etc/smokeping/etc/config
Presentation
charset = utf-8 #添加此行
vim /etc/smokeping/lib/Smokeping/Graphs.pm
#第160行下邊插入下邊一行
‘--font TITLE:20:"WenQuanYi Zen Hei Mono"‘,
"DEF:maxping=$cfg->{General}{datadir}${host}.rrd:median:AVERAGE",
設置開機啟動
chmod +x /etc/rc.d/rc.local
echo "/etc/smokeping/bin/smokeping --logfile=/var/log/smokeping.log 2>&1 &" >> /etc/rc.local
設置完畢,啟動Apache、SmorkePing服務
systemctl restart httpd.service
/etc/smokeping/bin/smokeping
好了,SmokePing設置就好了,打開瀏覽器輸入ip/smokeping,如下圖所示:
技術分享圖片


設置檢測源ip,填入到/etc/smokeping/etc/config中
vi /etc/smokeping/etc/config

  • MyServer
    menu = 出口網絡監控
    title = 監控統計
    ++ dianxin-xa
    menu = 西安電信
    title = 西安電信
    alerts = someloss
    host = 36.40.36.106
  • Tencent
    menu = 騰訊
    title = 騰訊監控
    ++ Tencent-Video
    menu = 騰訊視頻
    title = v.qq.com
    alerts = someloss
    host = 113.142.52.149
    ++ Tencent-Index
    menu = 騰訊首頁
    title = www.qq.com
    alerts = someloss
    host = www.qq.com
  • yy
    menu = 歪歪
    title =歪歪監控
    ++waiwai-Video
    menu = 歪歪直播
    title = www.yy.com
    alerts = someloss
    host = www.yy.com
    修改完配置,需要重啟SmokePing服務,重啟服務必須先殺掉正在運行的服務,才能重新啟動,負責是沒辦法重啟的。
    查看PID
    pgrep -l smokeping
    殺掉pid
    kill pid
    重啟啟動服務
    /etc/smokeping/bin/smokeping
    再打開,如圖所示:
    技術分享圖片
    從效果圖和配置文件對比來理解,顯示效果測層次感是根據+的數量逐層遞增的,123層。
    以上為測試內容,可根據實際需求情況進行調測。
    上述配置web訪問是直接訪問的,不安全,如果需要加入安全訪問控制,請修改apache的httpd.conf配置,下面粗體標記部分
    # SmokePing
    Alias /cache "/etc/smokeping/cache/"
    Alias /cropper "/etc/smokeping/htdocs/cropper/"
    Alias /smokeping "/etc/smokeping/htdocs/"

<Directory "/etc/smokeping/">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi

AllowOverride AuthConfig
Order allow,deny
Allow from all
AuthName "smokeping"
AuthType Basic
AuthUserFile /etc/smokeping/htdocs/htpasswd

Require valid-user

DirectoryIndex smokeping.fcgi
</Directory>
設置訪問的用戶名和密碼
htpasswd -c /etc/smokeping/htdocs/htpasswd admin
New password:
Re-type new password:
Adding password for user admin
重啟apache
systemctl restart httpd.service
技術分享圖片
輸入用戶名密碼就OK了。

監控軟件之SmokePing