(一)简介
smokeping是对IDC网络质量,稳定性等最好的检测工具,包括常规的 ping,dig,echoping,curl等,可以监视www服务器性能,监视dns查询性能,监视ssh性能等。底层也是 rrdtool 做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示。

smokeping的优点:
最佳的画图功能,延迟和丢包用颜色和阴影表示很直观。
免费和开源,作者是MRTG和RRDtool作者。
支持主从的分布式模式。
可以自定义报警功能。

smokeping架构组件:
smokeping 是一个用 perl 写的程序,所以不需要安装,但是他需要使用一些工具。Smokeping 有以下组件组成:RRDtool、Fping、Echoping、Curl、Dig、SSh、Perl 模块,Perl、FCGI、Apache 等。

Smokeping环境:
CentOS7.4 +Smokeping2.6.11

(二)安装
1,关闭selinux

[root@localhost tmp]# setenforce 0
[root@localhost tmp]# vim /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost tmp]# source  /etc/selinux/config 

2,安装相关依赖的包
[root@localhost tmp]# yum install -y rrdtool wqy* fping gcc echoping curl bind-utils httpd httpd-devel perl perl-FCGI perl-CGI perl-CGI-SpeedyCGI perl-CGI-SpeedyCGI perl-libwww-perl perl-Socket6 perl-Net-Telnet perl-Net-OpenSSH perl-Net-DNS perl-LDAP perl-IO-Socket-SSL perl-ExtUtils-MakeMaker rrdtool-perl perl-Sys-Syslog perl-RadiusPerl perl-Time-HiRes perl-RRD-Simple libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel mod_fastcgi

3,官网下载相应的安装包(https://oss.oetiker.ch/smokeping/

[root@localhost tmp]# wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz
--2018-01-18 18:28:30--  https://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz
Resolving oss.oetiker.ch (oss.oetiker.ch)... 46.140.183.210, 2a02:aa08:e000:1e00::d2
Connecting to oss.oetiker.ch (oss.oetiker.ch)|46.140.183.210|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 417338 (408K) [application/x-gzip]
Saving to: ‘smokeping-2.6.11.tar.gz’

100%[=======================================================================================>] 417,338     63.2KB/s   in 6.5s   

2018-01-18 18:28:39 (63.2 KB/s) - ‘smokeping-2.6.11.tar.gz’ saved [417338/417338]

4,编译安装smokeping

#请注意在configure前需要先build相应的perl模块,否则有报错。
[root@localhost tmp]# ls
ks-script-HudzSv  smokeping-2.6.11.tar.gz  yum.log
[root@localhost tmp]# tar xf smokeping-2.6.11.tar.gz 
[root@localhost tmp]# cd smokeping-2.6.11
[root@localhost smokeping-2.6.11]# ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
[root@localhost smokeping-2.6.11]# ./configure --prefix=/usr/local/smokeping
[root@localhost smokeping-2.6.11]# gmake install

5,配置smokeping
5.1,创建相应的目录并赋予权限

[root@localhost smokeping-2.6.11]# cd /usr/local/smokeping/
[root@localhost smokeping]# ll
total 0
drwxr-xr-x. 2 root root  75 Jan 18 19:35 bin
drwxr-xr-x. 3 root root 137 Jan 18 19:35 etc
drwxr-xr-x. 3 root root  48 Jan 18 19:35 htdocs
drwxr-xr-x. 3 root root 100 Jan 18 19:35 lib
drwxr-xr-x. 3 root root  17 Jan 18 19:35 share
drwxr-xr-x. 6 root root  67 Jan 18 19:34 thirdparty
[root@localhost smokeping]# mkdir var cache data
[root@localhost smokeping]# chown apache.apache var/ cache/ data/
[root@localhost smokeping]# ll
total 0
drwxr-xr-x. 2 root   root    75 Jan 18 19:35 bin
drwxr-xr-x. 2 apache apache   6 Jan 18 19:48 cache
drwxr-xr-x. 2 apache apache   6 Jan 18 19:48 data
drwxr-xr-x. 3 root   root   137 Jan 18 19:35 etc
drwxr-xr-x. 3 root   root    48 Jan 18 19:35 htdocs
drwxr-xr-x. 3 root   root   100 Jan 18 19:35 lib
drwxr-xr-x. 3 root   root    17 Jan 18 19:35 share
drwxr-xr-x. 6 root   root    67 Jan 18 19:34 thirdparty
drwxr-xr-x. 2 apache apache   6 Jan 18 19:48 var

5.2,备份fcgi文件与config文件

[root@localhost smokeping]# cp /usr/local/smokeping/htdocs/smokeping.fcgi.dist  /usr/local/smokeping/htdocs/smokeping.fcgi
[root@localhost smokeping]# cp /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/config

*( smokeping七大组件:general(普通设置) 、alerts(警报设置)、Datebase(数据库参数)、presentation(网络自定义)、slaves(从smokeping定义)、targets(目标设置——“含插件定义”))

5.3.修改config文件general配置,把cgiurl = http://some.url/smokeping.cgi中的some.url换成你的IP地址

[root@localhost smokeping]# sed -i 's|some.url|172.20.66.111|g' /usr/local/smokeping/etc/config
[root@localhost smokeping]# vim etc/config

*** General ***

owner    = Peter Random
contact  = some@address.nowhere
mailhost = my.mail.host
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   = cache
datadir  = /usr/local/smokeping/data
piddir  = /usr/local/smokeping/var
cgiurl   = http://172.20.66.111/smokeping.cgi

5.4,Alerts和database配置

*** Alerts ***
to = alertee@address.somewhere
from = smokealert@company.xy

+someloss
type = loss
# in percent
pattern = >0%,*12*,>0%,*12*,>0%
comment = loss 3 times  in a row

#新增rtt监测机制
+rttdetect
type = rtt
# in milliseconds
pattern = <55,<55,<55,>55,>55,>55
comment = 每次发出60个包,连续3次轮询检查延时超过55毫秒

*** Database ***
######默认300秒ping20次,修改为120秒ping30次
step     = 120
pings    = 30

5.5,presentation配置,添加utf-8字符集和在detail部分,修改历史数据展示的时间

*** Presentation ***
###添加UTF-8中文字符集
charset = utf-8

template = /usr/local/smokeping/etc/basepage.html.dist

+ 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

width = 600
height = 50
range = 10h

+ detail

width = 600
height = 200
unison_tolerance = 2

"Last 10 Minutes" 10m
"Last 30 Minutes" 30m
"Last 4 Hours" 4h  
"Last 12 Hours" 12h
"Last 1 Days" 24h
"Last 3 Days" 3d
"Last 1 Weeks" 7d
"Last 1 Mouths" 30d
"Last Half years" 180d
"Last 1 years" 365d
#"Last 3 Hours"    3h
#"Last 30 Hours"   30h
#"Last 10 Days"    10d
#"Last 400 Days"   400d

6,修改账号文件权限
[root@localhost smokeping]# chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
7,创建登录账号和密码

[root@localhost smokeping]# htpasswd -c /usr/local/smokeping/htdocs/htpasswd admin
New password: 
Re-type new password: 
Adding password for user admin
[root@localhost smokeping]# 

7,设置httpd的访问路径

[root@smokeping smokeping]# vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html"

Alias /cache "/usr/local/smokeping/cache/"
Alias /cropper "/usr/local/smokeping/htdocs/cropper/"
Alias /smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi"

<Directory "/usr/local/smokeping">
    AllowOverride None
    Options All
    AddHandler cgi-script .fcgi .cgi
    Order allow,deny
    Allow from all
    AuthName "Smokeping"
    AuthType Basic
    AuthUserFile /usr/local/smokeping/htdocs/htpasswd
    Require valid-user
    DirectoryIndex smokeping.fcgi
</Directory> 

8,关闭防火墙

[root@localhost smokeping]# service firewalld stop
[root@localhost smokeping]# systemctl stop iptables.service

9.设置开机启动
`[root@localhost smokeping]# echo "/usr/local/smokeping/bin/smokeping &">> /etc/rc.local``

10,把smokeping做成服务
[root@localhost ~]#chkconfig --add smokeping
[root@localhost ~]#chkconfig smokeping on
[root@localhost ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

  If you want to list systemd services use 'systemctl list-unit-files'.
  To see services enabled on particular target use
  'systemctl list-dependencies [target]'.

netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
smokeping 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]# /etc/init.d/smokeping start
Starting smokeping (via systemctl): Warning: smokeping.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[ OK ]
[root@localhost ~]# /etc/init.d/smokeping status
● smokeping.service - SYSV: Smokeping init.d script
Loaded: loaded (/etc/rc.d/init.d/smokeping; bad; vendor preset: disabled)
Active: active (running) since Mon 2018-01-22 11:35:53 CST; 1s ago
Docs: man:systemd-sysv-generator(8)
Process: 31355 ExecStop=/etc/rc.d/init.d/smokeping stop (code=exited, status=0/SUCCESS)
Process: 31386 ExecStart=/etc/rc.d/init.d/smokeping start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/smokeping.service
└─31393 /usr/local/smokeping/bin/smokeping [FPing]

Jan 22 11:35:53 localhost.localdomain systemd[1]: Starting SYSV: Smokeping init.d script...
Jan 22 11:35:53 localhost.localdomain smokeping[31389]: Starting syslog logging
Jan 22 11:35:53 localhost.localdomain smokeping[31393]: Smokeping version 2.006011 successfully launched.
Jan 22 11:35:53 localhost.localdomain smokeping[31393]: Not entering multiprocess mode for just a single probe.
Jan 22 11:35:53 localhost.localdomain smokeping[31393]: FPing: probing 5 targets with step 120 s and offset 110 s.
Jan 22 11:35:53 localhost.localdomain smokeping[31386]: Starting Smokeping: [ OK ]
Jan 22 11:35:53 localhost.localdomain systemd[1]: Started SYSV: Smokeping init.d script.
Warning: smokeping.service changed on disk. Run 'systemctl daemon-reload' to reload units.

备注,以下是常用的配置文件和使用脚本
############smokeping配置文件##########
[root@localhost ~]# cat /usr/local/smokeping/etc/config
** General ***

owner = lqb
contact = some@address.nowhere
mailhost = my.mail.host
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 = cache
datadir = /usr/local/smokeping/data
piddir = /usr/local/smokeping/var
cgiurl = http://172.20.66.111/smokeping.cgi
smokemail = /usr/local/smokeping/etc/smokemail.dist
tmail = /usr/local/smokeping/etc/tmail.dist
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 = no

** Alerts ***
to = alertee@address.somewhere
from = smokealert@company.xy

+someloss
type = loss
in percent
pattern = >0%,12,>0%,12,>0%
comment = loss 3 times in a row

新增rtt监测机制
+rttdetect
type = rtt
in milliseconds
pattern = <55,<55,<55,>55,>55,>55
comment = 每次发出60个包,连续3次轮询检查延时超过55毫秒

** Database ***

step = 120
pings = 30

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 ***
添加UTF-8中文字符集
charset = utf-8

template = /usr/local/smokeping/etc/basepage.html.dist

  • 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 = 50
range = 10h

  • detail

width = 600
height = 200
unison_tolerance = 2

"Last 2 Minutes" 2m
"Last 30 Minutes" 30m
"Last 4 Hours" 4h
"Last 12 Hours" 12h
"Last 1 Days" 24h
"Last 3 Days" 3d
"Last 1 Weeks" 7d
"Last 1 Mouths" 30d
"Last Half years" 180d
"Last 1 years" 365d
"Last 3 Hours" 3h
"Last 30 Hours" 30h
"Last 10 Days" 10d
"Last 400 Days" 400d

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

** Probes ***

  • FPing

binary = /usr/sbin/fping

** Slaves ***
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+boomer
display_name=boomer
color=0000ff

+slave2
display_name=another
color=00ff00

** Targets ***

probe = FPing

menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of ppdai Company. \
Here you will learn all about the latency of our network.

  • Test
    menu= Targets
    parents = owner:/Test/James location:/

++Localhost
menu = Localhost
title = Localhost
alerts = someloss
slaves = boomer slave2
host = 192.168.99.98

  • Other
    menu = 全国网络监控
    title = 监控统计
    ++ dianxin
    menu = 电信网络监控
    title = 电信网络监控列表
    host = /Other/dianxin/dianxin-wx /Other/dianxin/dianxin-hf
    +++ dianxin-wx
    menu = 无锡监控
    title = 无锡监控
    alerts = someloss
    host = 192.168.15.99
    +++ dianxin-hf
    menu = 合肥监控
    title = 合肥监控
    alerts = someloss
    host = 172.21.24.99

+++ dianxin-cs
menu = 长沙监控
title = 长沙监控
alerts = someloss
host = 172.21.100.12
+++ dianxin-shanghai
menu = 上海监控
title = 上海监控
alerts = someloss
host = 172.20.66.110

#########smokeping,启动脚本文件#########
[root@localhost ~]# cat /etc/init.d/smokeping
#!/bin/bash

chkconfig: 2345 80 05
Description: Smokeping init.d script
Hacked by : How2CentOS - http://www.how2centos.com
Get function from functions library
. /etc/init.d/functions
Start the service Smokeping
start() {
echo -n "Starting Smokeping: "
/usr/local/smokeping/bin/smokeping >/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