[关闭]
@cdmonkey 2016-07-27T08:38:42.000000Z 字数 11836 阅读 1710

SmokePing

运维工具


一、简介

官网:http://oss.oetiker.ch/smokeping/

Smokeping是rrdtool的作者的作品,主要是监视网络性能,其底层也是rrdtool做支持,特点是画的图非常漂亮,网络丢包和延迟用颜色和阴影来表示。它可以采用多种探测方式,包括fping、echoping、dig、curl等,以及易用的、可扩展的插件。很有特色的报警设置,不只是简单的设置一个阀值。

主从的工作方式,可以在多个节点收集同一个监测点的数据。从机会自己去检查监测点的情况(loss and rtt),并将数值提交给主机(via smokeping.cgi)。值得注意的是,从并不需要配置文件,每次从提交完数据以后,会询问主它自己的配置文件是否有变动,如果有变动,从会进行更新。

配置方法我就简单说说好了:

About RTT

RTT(Round-Trip Time):简单说它是一个数据报在网络上两点中间往返一次的时间。是影响TCP性能和表征网络运行状况的重要参数。在网络中实时、准确地测量大量TCP设备和系统的RTT参数是网络管的重要环节之一。Smokeping就是这样的一个自动测试系统,它向目标设备和系统发送各种类型的测试数据包,测量、记录和展示RTT。

Median RTT:它是“中间数”而并不是平均值。Smokeping有多种类型的探针,探针在默认的设置下,每300秒向目标设备发送20个探测数据包。假如这20个数据包都返回的话,那么它就记录下这20个RTT,所以这个中间数就是第十个包的RTT。如果有五个包丢失的话,那么这个中间数就是第八个返回的包的RTT值。

Avg RTT:它是每一个测试回合中所有RTT的算术评价值。

Avg pkt loss:丢包率。

二、安装

1. 准备工作

首先确认下操作系统信息:

  1. [root@smokeping ~]# cat /etc/redhat-release
  2. CentOS release 6.5 (Final)
  3. --------------
  4. [root@smokeping ~]# uname -r
  5. 2.6.32-431.el6.x86_64
  6. #IP Address:
  7. [root@smokeping ~]# ifconfig eth0 |awk -F '[ :]+' 'NR==2 {print $4}'
  8. 10.10.200.23

YUM Source:

  1. #EPEL:
  2. wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
  3. rpm -ivh epel-release-6-8.noarch.rpm
  4. [root@smokeping ~]# rpm -qa|grep epel
  5. epel-release-6-8.noarch

2. 安装过程

Install Apache

  1. yum install -y httpd httpd-devel

Install RRDTool

  1. #首先安装一些依赖包:
  2. yum install -y libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel \
  3. gd gd-devel libiconv libiconv-devel glib glib-devel pango pango-devel freetype freetype-devel \
  4. fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel popt-devel perl-ExtUtils-Embed \
  5. libidn libidn-devel
  6. yum install -y perl-Compress-Zlib perl-HTML-Tagset perl-HTML-Parser perl-libwww-perl \
  7. xorg-x11-fonts-Type1 ruby libdbi
  8. yum install -y fonts-chinese.noarch
  9. yum install -y rrdtool-perl

这里我们选择编译安装,目的是可以指定相应的路径,方便后续查找路径使用。

  1. [root@smokeping tools]# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.8.tar.gz
  2. [root@smokeping tools]# tar zxvf rrdtool-1.4.8.tar.gz
  3. [root@smokeping tools]# cd rrdtool-1.4.8
  4. ./configure --prefix=/usr/local/rrdtool --disable-tcl --disable-pytho
  5. make && make install
  6. --------------------
  7. #安装后验证,出现下面的信息就说明安装成功了。安装完一定要验证,不一定安装完成后就是成功的。
  8. [root@smokeping ~]# /usr/local/rrdtool/bin/rrdtool -v
  9. RRDtool 1.4.8 Copyright 1997-2013 by Tobias Oetiker <tobi@oetiker.ch>
  10. Compiled Apr 9 2015 10:41:16
  11. Usage: rrdtool [options] command command_options
  12. Valid commands: create, update, updatev, graph, graphv, dump, restore,
  13. last, lastupdate, first, info, fetch, tune,
  14. resize, xport, flushcached
  15. RRDtool is distributed under the Terms of the GNU General
  16. Public License Version 2. (www.gnu.org/copyleft/gpl.html)
  17. For more information read the RRD manpages

Install cgilib

  1. [root@smokeping tools]# wget http://down1.chinaunix.net/distfiles/cgilib-0.5.tar.gz
  2. [root@smokeping tools]# tar zxvf cgilib-0.5.tar.gz
  3. [root@smokeping tools]# cd cgilib-0.5
  4. [root@smokeping cgilib-0.5]# make
  5. [root@smokeping cgilib-0.5]# cp libcgi.a /usr/local/lib
  6. [root@smokeping cgilib-0.5]# cp cgi.h /usr/include

Install fping

  1. [root@smokeping ~]# yum install -y fping
  2. #查看安装路径,方便后续填写路径:
  3. [root@smokeping ~]# which fping
  4. /usr/sbin/fping

Install echoping

  1. wget http://jaist.dl.sourceforge.net/project/echoping/echoping/6.0.2/echoping-6.0.2.tar.gz
  2. [root@smokeping tools]# tar zxvf echoping-6.0.2.tar.gz
  3. [root@smokeping tools]# cd echoping-6.0.2
  4. [root@smokeping echoping-6.0.2]# ./configure
  5. [root@smokeping echoping-6.0.2]# make && make install
  6. --------------------
  7. #查看下安装路径:
  8. [root@smokeping echoping-6.0.2]# whereis echoping
  9. echoping: /usr/local/bin/echoping /usr/local/lib/echoping

Install FCGI

  1. wget http://cpan.communilink.net/authors/id/F/FL/FLORA/FCGI-0.74.tar.gz
  2. [root@smokeping tools]# tar zxvf FCGI-0.74.tar.gz
  3. [root@smokeping tools]# cd FCGI-0.74
  4. [root@smokeping FCGI-0.74]# perl Makefile.PL
  5. [root@smokeping FCGI-0.74]# make && make install

Install mod_fastcgi

因为是通过yum安装的www服务,所以模块的安装就和基于源码编译安装的有很大的不同。

  1. #还要安装一些必要的依赖包:
  2. yum install -y httpd-devel libtool apr apr-devel
  3. #下载源码包:
  4. wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
  5. [root@smokeping tools]# tar zxvf mod_fastcgi-2.4.6.tar.gz
  6. [root@smokeping tools]# cd mod_fastcgi-2.4.6
  7. [root@smokeping mod_fastcgi-2.4.6]# cp Makefile.AP2 Makefile
  8. [root@smokeping mod_fastcgi-2.4.6]# vim Makefile
  9. #修改为下面的路径:
  10. top_dir = /usr/lib64/httpd
  11. [root@smokeping mod_fastcgi-2.4.6]# make && make install
  12. --------------------
  13. #验证一下:
  14. [root@smokeping mod_fastcgi-2.4.6]# ls /usr/lib64/httpd/modules/|grep mod_fastcgi.so
  15. mod_fastcgi.so

最后要加载模块:

  1. [root@smokeping ~]# vim /etc/httpd/conf/httpd.conf
  2. #确认有如下一行,没有则添加:
  3. LoadModule fastcgi_module modules/mod_fastcgi.so

Install Smokeping

  1. wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.8.tar.gz
  2. [root@smokeping tools]# tar zxvf smokeping-2.6.8.tar.gz
  3. [root@smokeping tools]# cd smokeping-2.6.8
  4. [root@smokeping smokeping-2.6.8]# ./configure --prefix=/usr/local/smokeping
  5. #注意,这里一定会出现下面的报错信息:
  6. ** Aborting Configure ******************************
  7. If you know where perl can find the missing modules, set
  8. the PERL5LIB environment variable accordingly.
  9. FIRST though, make sure that 'perl' starts the perl
  10. binary you want to use for SmokePing.
  11. Now you can install local copies of the missing modules
  12. by running
  13. ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
  14. The RRDs perl module is part of RRDtool. Either use the rrdtool
  15. package provided by your OS or install rrdtool from source.
  16. If you install from source, the RRDs module is located
  17. PREFIX/lib/perl
  18. #直接执行脚本,接下来就是在线等,漫长的等待:
  19. [root@smokeping smokeping-2.6.8]# ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
  20. #这回就没问题了。
  21. [root@smokeping smokeping-2.6.8]# ./configure --prefix=/usr/local/smokeping
  22. [root@smokeping smokeping-2.6.8]# /usr/bin/gmake install
  1. #注意:这里的安装没有用过,暂且留下。
  2. yum install -y perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI

三、配置使用

1. smokeping

  1. [root@smokeping ~]# vim /usr/local/smokeping/bin/smokeping
  2. #把第八行内容:
  3. use lib qw(); # PERL5LIB
  4. #修改为:
  5. use lib qw(/usr/local/rrdtool/lib/perl/5.10.1); # PERL5LIB

2. config

只帖出要修改的部分,没有出现的不用修改。

  1. [root@smokeping ~]# cd /usr/local/smokeping/htdocs/
  2. [root@smokeping htdocs]# cp smokeping.fcgi.dist smokeping.fcgi
  3. [root@smokeping htdocs]# cd ../etc/
  4. [root@smokeping etc]# chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
  5. ---------------------
  6. [root@smokeping etc]# cp config.dist config
  7. [root@smokeping etc]# vim config
  8. #Smokeping的配置基本都在这个文件内。
  9. *** General ***
  10. #第一部分属于基本配置,注意下面两个与图片相关的路径设置,如果配置不对的话,打开首页时图片会显示不出来。
  11. ...
  12. imgcache = /usr/local/smokeping/htdocs/img
  13. imgurl = http://10.10.200.23/smokeping/img
  14. datadir = /usr/local/smokeping/data
  15. piddir = /usr/local/smokeping/var
  16. cgiurl = http://10.10.200.23/smokeping/smokeping.fcgi
  17. ---------------------
  18. *** Database ***
  19. step = 60
  20. pings = 20
  21. ---------------------
  22. *** Presentation ***
  23. charset = zh_CN.UTF-8
  24. ---------------------
  25. *** Probes ***
  26. + FPing
  27. binary = /usr/sbin/fping
  28. ---------------------
  29. ++ James
  30. menu = James
  31. title =James
  32. #alerts = someloss
  33. #slaves = boomer slave2
  34. host = 8.8.8.8

3. Configure HTTP

创建目录:

  1. [root@smokeping ~]# cd /usr/local/smokeping/
  2. #创建下面三个目录用于保存smokeping的数据:
  3. [root@smokeping smokeping]# mkdir cache data var
  4. [root@smokeping smokeping]# chown apache.apache cache data var
  5. [root@smokeping smokeping]# ln -s /usr/local/smokeping/cache /usr/local/smokeping/htdocs/cache
  6. ---------------------
  7. [root@smokeping smokeping]# mkdir htdocs/img
  8. [root@smokeping smokeping]# chown apache.apache htdocs/img/

修改配置文件:

  1. [root@smokeping ~]# vim /etc/httpd/conf/httpd.conf
  2. #找到下面这行,去掉注释,并修改为:
  3. ServerName localhost:80
  4. #找到下面这行,去掉注释:
  5. AddHandler cgi-script .cgi
  6. ---------------------
  7. #在配置文件最后面添加如下内容:
  8. Alias /smokeping/ "/usr/local/smokeping/htdocs/"
  9. <Directory "/usr/local/smokeping/">
  10. AllowOverride None
  11. Options All
  12. AddHandler cgi-script .fcgi .cgi
  13. Order allow,deny
  14. Allow from all
  15. DirectoryIndex smokeping.fcgi
  16. </Directory>

创建启动脚本:

  1. [root@smokeping ~]# mv smokeping.sh /etc/init.d/smokeping
  2. [root@smokeping ~]# chmod 755 /etc/init.d/smokeping
  3. #注意脚本格式,要不然会报“没有那个文件或目录”的错误信息。
  4. [root@smokeping ~]# dos2unix /etc/init.d/smokeping /etc/init.d/smokeping

最后,启动服务并设置必要服务开机启动。

  1. #开启服务之前,可以对配置文件进行检查:
  2. [root@smokeping ~]# /usr/local/smokeping/bin/smokeping --check
  3. Configuration file '/usr/local/smokeping/bin/../etc/config' syntax OK.
  4. ---------------------
  5. [root@smokeping ~]# chkconfig smokeping on
  6. [root@smokeping ~]# chkconfig httpd on
  7. [root@smokeping ~]# /etc/init.d/smokeping start
  8. Starting Smokeping: [ OK ]
  9. [root@smokeping ~]# /etc/init.d/httpd start
  10. Starting httpd: [ OK ]

至此,我们就可以通过浏览器打开监控页面进行监控了。

此处输入图片的描述

4. 页面认证

  1. #第一步,创建用户
  2. [root@smokeping ~]# htpasswd -cb /usr/local/smokeping/etc/htpasswd.users admin admin
  3. Adding password for user admin
  4. [root@smokeping ~]# ll /usr/local/smokeping/etc/htpasswd.users
  5. -rw-r--r--. 1 root root 20 4 9 17:18 /usr/local/smokeping/etc/htpasswd.users
  1. #第二步,修改配置文件(修改定义站点目录的那部分)
  2. [root@smokeping ~]# vim /etc/httpd/conf/httpd.conf
  3. Alias /smokeping/ "/usr/local/smokeping/htdocs/"
  4. <Directory "/usr/local/smokeping/">
  5. AllowOverride None
  6. Options All
  7. AddHandler cgi-script .fcgi .cgi
  8. Order allow,deny
  9. Allow from all
  10. DirectoryIndex smokeping.fcgi
  11. #添加下面这四行指令:
  12. AuthName "Smokeping Access"
  13. AuthType Basic
  14. AuthUserFile /usr/local/smokeping/etc/htpasswd.users
  15. Require valid-user
  16. </Directory>
  17. ---------------------
  18. #最后要重启服务:
  19. [root@smokeping ~]# /etc/init.d/httpd restart
  20. Stopping httpd: [ OK ]
  21. Starting httpd: [ OK ]

那么如何修添加用户以及改用户的密码呢?(详细用法

  1. #如何在原有密码文件中增加下一个用户:
  2. [root@smokeping ~]# htpasswd -b /usr/local/smokeping/etc/htpasswd.users cdmonkey cdmonkey
  3. Adding password for user cdmonkey
  4. [root@smokeping ~]# cat /usr/local/smokeping/etc/htpasswd.users
  5. admin:25SPfMgnV8K12
  6. cdmonkey:iUfdOiqd7O.fo
  7. #修改用户密码,即先删除指定用户,再添加用户命令创建用户即可实现修改密码的功能:
  8. [root@smokeping ~]# htpasswd -D /usr/local/smokeping/etc/htpasswd.users admin
  9. Deleting password for user admin
  10. [root@smokeping ~]# htpasswd -b /usr/local/smokeping/etc/htpasswd.users admin suixingpay.123
  11. Adding password for user admin

四、监控实例

配置文件详解:http://blog.chinaunix.net/uid-23886490-id-3135554.html

  1. *** General ***
  2. #第一部分属于基本配置。
  3. owner = cdmonkey
  4. contact = wang_hz@suixingpay.com
  5. mailhost = my.mail.host
  6. sendmail = /usr/sbin/sendmail
  7. # NOTE: do not put the Image Cache below cgi-bin
  8. # since all files under cgi-bin will be executed ... this is not
  9. # good for images.
  10. imgcache = /usr/local/smokeping/htdocs/img
  11. imgurl = http://10.10.200.23/smokeping/img
  12. datadir = /usr/local/smokeping/data
  13. piddir = /usr/local/smokeping/var
  14. cgiurl = http://10.10.200.23/smokeping/smokeping.fcgi
  15. smokemail = /usr/local/smokeping/etc/smokemail.dist
  16. tmail = /usr/local/smokeping/etc/tmail.dist
  17. # specify this to get syslog logging
  18. syslogfacility = local0
  19. # each probe is now run in its own process
  20. # disable this to revert to the old behaviour
  21. # concurrentprobes = no
  22. *** Alerts ***
  23. #第二部分是属于报警配置。
  24. to = wang_hz@suixingpay.com
  25. from = smokealert@company.xy
  26. +someloss
  27. type = loss
  28. # in percent
  29. pattern = >0%,*12*,>0%,*12*,>0%
  30. comment = loss 3 times in a row
  31. *** Database ***
  32. #第三部分是RRD数据库的配置。
  33. #注意下面这两个参数要在启动服务之前配置好,如果在服务启动后再配置这两个参数,需要把原来的rrd文件都删除,然后再启动服务才可以,所以这个一定要先配置好。
  34. #这里显示的就是其默认数值,表示每300s内执行20次ping的动作。
  35. step = 300
  36. pings = 20
  37. # consfn mrhb steps total
  38. AVERAGE 0.5 1 1008
  39. AVERAGE 0.5 12 4320
  40. MIN 0.5 12 4320
  41. MAX 0.5 12 4320
  42. AVERAGE 0.5 144 720
  43. MAX 0.5 144 720
  44. MIN 0.5 144 720
  45. *** Presentation ***
  46. #第四部分是关于网络状态的一些配置和解释,基本不需要更改。
  47. template = /usr/local/smokeping/etc/basepage.html.dist
  48. + charts
  49. menu = Charts
  50. title = The most interesting destinations
  51. ++ stddev
  52. sorter = StdDev(entries=>4)
  53. title = Top Standard Deviation
  54. menu = Std Deviation
  55. format = Standard Deviation %f
  56. ++ max
  57. sorter = Max(entries=>5)
  58. title = Top Max Roundtrip Time
  59. menu = by Max
  60. format = Max Roundtrip Time %f seconds
  61. ++ loss
  62. sorter = Loss(entries=>5)
  63. title = Top Packet Loss
  64. menu = Loss
  65. format = Packets Lost %f
  66. ++ median
  67. sorter = Median(entries=>5)
  68. title = Top Median Roundtrip Time
  69. menu = by Median
  70. format = Median RTT %f seconds
  71. #下面的两个模块(overview & detail)里面是图片大小设置,可以按需来设置。
  72. + overview
  73. width = 600
  74. height = 50
  75. range = 10h
  76. + detail
  77. width = 600
  78. height = 200
  79. unison_tolerance = 2
  80. "Last 3 Hours" 3h
  81. "Last 30 Hours" 30h
  82. "Last 10 Days" 10d
  83. "Last 400 Days" 400d
  84. + hierarchies
  85. ++ owner
  86. title = Host Owner
  87. ++ location
  88. title = Location
  89. *** Probes ***
  90. + FPing
  91. #第五部分是探针的配置,我们一般只用到fping,所以就只要以下配置就可以了,确定路径是否正确(这里还可以设置数据包的大小)。
  92. binary = /usr/sbin/fping
  93. #*** Slaves ***
  94. #第六分部是主从关系里面的从服务器相关配置。
  95. #secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
  96. #+boomer
  97. #display_name=boomer
  98. #color=0000ff
  99. #+slave2
  100. #display_name=another
  101. #color=00ff00
  102. *** Targets ***
  103. #第七部分是监控节点目标的配置。在这里可以单独配置一台服务器的监控情况,需要从服务器上取值的配置也是在这里配置。
  104. #需要注意一下:+代表一级菜单,+下面的++是继承上面的+成为二级菜单。而且可以有多个一级菜单和二级菜单。
  105. probe = FPing
  106. menu = Top
  107. title = Network Latency Grapher
  108. remark = Welcome to the SmokePing website of xxx Company. \
  109. Here you will learn all about the latency of our network.
  110. + Test
  111. menu= Targets
  112. #parents = owner:/Test/James location:/
  113. ++ James
  114. menu = James
  115. title =James
  116. #alerts = someloss
  117. #slaves = boomer slave2
  118. host = 8.8.8.8
  119. ++ MultiHost #在这里设置在一张图里画多个监测点的数值。
  120. menu = Multihost
  121. title = James and James as seen from Boomer
  122. host = /Test/James /Test/James~boomer

验证配置文件:

  1. [root@smokeping ~]# /usr/local/smokeping/bin/smokeping --check
  2. Configuration file '/usr/local/smokeping/bin/../etc/config' syntax OK.
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注