发布时间:2025-12-09 16:09:10 浏览次数:4
更多内容请点击 我的博客 查看,欢迎来访。
选择机房时,需要知道机房的网络请况,就需要用到网络监控软件smokeping。
smokeping由Perl语言写成,底层依赖于rrdtool和fping。
主要是监视网络性能,包括常规的ping,用echoping监控www服务器性能,监控dns查询性能和监控ssh性能等。底层时以rrdtool做支持,使用画图来表示网络丢包和延迟。
从监控图上的延时与丢包能分辨出你机房的网络是否稳定,是否为多线,是否为BGP机房,到各城市的3个运营商之间的网络,各是什么情况,如果出现问题,如何有针对性的解决。而且如果选择新机房的时候,可以根据smokeping的监控结果来判断这个机房是否适合。
smokeping整个系统正常运行需要:web服务器软件、smokeping主服务、探针,rrdtool。
smokeping拥有直观高效且漂亮的webUI,因此需要借助第三方web服务,默认使用的是apache服务,同时需要启用cgi模块。
smokeping主服务即smokeping工作进程,负责在后台(也可以前台)执行监测任务。
smokeping实际使用的监测工具即探针。默认探针是fping,常用探针例如:
更多关于探针的介绍可以参阅官方文档。
rrdtool(Round Robin Database Tool)即轮询调度数据库工具,使用C语言写成,是一种强大的绘图引擎,兼有时序数据库和绘图两种功能。rrdtool被许多监控平台所使用,如smokeping、cacti、open-falcon等。
访问 https://oss.oetiker.ch/smokeping/doc/smokeping_install.en.html 可以看到安装步骤。
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core)[root@localhost ~]# uname -r3.10.0-1062.4.1.el7.x86_64smokeping需要依赖系统上的其他工具和服务,除了Unix操作Perl组件。
Smokeping使用RRDtool进行记录和绘图。如果linux提供了一个带有perl支持的rrdtool包,那么可以使用它。如果没有或安装新版
[root@localhost ~]# yum install rrdtool perl-rrdtool openssl-devel -ysmokeping 2.7.2 以上需要 fping4.0 以上,因此需要手动编译。可以访问 http://www.fping.org/ 下载
[root@localhost ~]# wget http://www.fping.org/dist/fping-4.2.tar.gz[root@localhost ~]# tar -xzf fping-4.2.tar.gz[root@localhost ~]# cd fping-4.2[root@localhost fping-4.2]# ./configure[root@localhost fping-4.2]# make && make install需要它来运行echoping探测,做tcp ping,访问 https://github.com/bortzmeyer/echoping/ 进行查看。 http://bortzmeyer.github.io/echoping/ 官方说明,不在积极维护了。
[root@localhost ~]# wget https://fossies.org/linux/misc/old/echoping-6.0.2.tar.gz[root@localhost ~]# tar xzf echoping-6.0.2.tar.gz[root@localhost ~]# cd echoping-6.0.2[root@localhost echoping-6.0.2]# yum install -y popt-devel[root@localhost echoping-6.0.2]# ./configure # 如果报错使用下面的配置[root@localhost echoping-6.0.2]# ./configure --with-ssl --without-libidn[root@localhost echoping-6.0.2]# make && make installhttp://httpd.apache.org/
重要的是,要有一个web服务器,它允许运行CGI,最好是FastCGI脚本。如果使用的是Apache,强烈建议使用suexec系统作为特定用户运行CGI脚本。
有关更多信息,请查看 http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html 和 http://httpd.apache.org/docs/2.2/mod/mod_suexec.html 。
注意smokeping是fcgi程序,因此apache 需要安装mod_fcgid, http的版本是 2.4.6
[root@localhost ~]# yum install httpd httpd-devel -y[root@localhost ~]# yum install mod_fcgid -y[root@localhost ~]# systemctl enable httpdCreated symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.[root@localhost ~]# systemctl start httpd# 查看Apache默认监听端口[root@localhost ~]# cat /etc/httpd/conf/httpd.conf | grep Listen | grep -v "#"Listen 80# 查看端口及服务[root@localhost ~]# netstat -antp | grep httpdtcp6 0 0 :::80 :::* LISTEN 8572/httpd # 但是外部是不同的,需要开启CentOS的防火墙fireall-cmd[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=80/tcpsuccess# 操作完成后重载[root@localhost ~]# firewall-cmd --reloadsuccess这时候访问该主机的IP http://xxx.xxx.xxx.xxx/ 即可以看到Apache的页面。
安装的版本为 smokeping-2.7.3 ,为2019年11月16日最新
[root@localhost ~]# wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.7.3.tar.gz[root@localhost ~]# tar xzf smokeping-2.7.3.tar.gz[root@localhost ~]# cd smokeping-2.7.3[root@localhost smokeping-2.7.3]# ./configure --prefix=/opt/smokeping** Ready to install Smokeping ******************************Settings:PERL5LIB = not setPERL = /usr/bin/perlThe Smokeping Makefiles use GNU make functionality.Continue installation with/usr/bin/gmake install出现上面的错误,表示没有指定PERL5LIB,下面将加上
[root@localhost smokeping-2.7.3]# ./configure --prefix=/opt/smokeping PERL5LIB=/usr/lib64/perl5/** Ready to install Smokeping ******************************Settings:PERL5LIB = /usr/lib64/perl5/PERL = /usr/bin/perlThe Smokeping Makefiles use GNU make functionality.Continue installation with/usr/bin/gmake install[root@localhost smokeping-2.7.3]# /usr/bin/gmake installMaking install in thirdpartygmake[1]: 进入目录“/root/smokeping-2.7.3/thirdparty”GEN touchSuccessfully installed FCGI-0.78Successfully installed HTML-Tagset-3.20Successfully installed HTML-Parser-3.72Successfully installed CGI-4.40 (upgraded from 3.59)Successfully installed CGI-Fast-2.13 (upgraded from 1.09)Successfully installed Config-Grammar-1.12Successfully installed Socket6-0.29Successfully installed Net-SSLeay-1.85Successfully installed Mozilla-CA-20180117Successfully installed IO-Socket-SSL-2.060Successfully installed Digest-HMAC-1.03Successfully installed Net-Telnet-3.04Successfully installed Net-OpenSSH-0.78Successfully installed Net-SNMP-v6.0.1Successfully installed Convert-ASN1-0.27Successfully installed perl-ldap-0.65Successfully installed IO-Socket-IP-0.39Successfully installed Net-DNS-1.19Successfully installed IO-Tty-1.12Successfully installed URI-1.74Successfully installed LWP-MediaTypes-6.02Successfully installed Encode-Locale-1.05Successfully installed IO-HTML-1.001Successfully installed HTTP-Date-6.02Successfully installed HTTP-Message-6.18Successfully installed File-Listing-6.04Successfully installed HTTP-Negotiate-6.01Successfully installed HTTP-Daemon-6.01Successfully installed Try-Tiny-0.30Successfully installed Net-HTTP-6.18Successfully installed HTTP-Cookies-6.04Successfully installed WWW-RobotRules-6.02Successfully installed libwww-perl-6.36Successfully installed ExtUtils-MakeMaker-7.34 (upgraded from 6.63_02)Successfully installed Net-IP-1.26Successfully installed Data-HexDump-0.02Successfully installed Authen-Radius-0.29Successfully installed Path-Tiny-0.10838 distributions installed# 安装成功需要建立三个文件夹,data用来存放 rrd 文件,var用来存放 smokeping 的 pid,/var/log用来存放 smokeping.log
[root@localhost ~]# cd /opt/smokeping# 从示例文件中,可以看到需要创建下面即可目录[root@localhost smokeping]# cat etc/config.dist | grep '/opt/smokeping'imgcache = /opt/smokeping/cachedatadir = /opt/smokeping/datapiddir = /opt/smokeping/varsmokemail = /opt/smokeping/etc/smokemail.disttmail = /opt/smokeping/etc/tmail.disttemplate = /opt/smokeping/etc/basepage.html.distsecrets=/opt/smokeping/etc/smokeping_secrets.dist# 创建需要的目录[root@localhost smokeping]# mkdir data cache var[root@localhost smokeping]# chown apache:apache cache data var[root@localhost smokeping]# chmod 777 data cache var# 创建日志文件[root@localhost smokeping]# touch /var/log/smokeping.log[root@localhost smokeping]# chown apache:apache /var/log/smokeping.log接下来进行手动启动
[root@localhost smokeping]# bin/smokeping --logfile=/var/log/smokeping.logERROR: /opt/smokeping/bin/../etc/config, line 112: ERROR: FPing 'binary' does not point to an executable# 启动失败,因为之前安装fping的路径是不一样的,需要进行修改,【如果前面已经修改过,则不用修改了】[root@localhost smokeping]# whereis fpingfping: /usr/local/sbin/fping[root@localhost smokeping]# vim etc/config# 找到112行修改# binary = /usr/sbin/fpingbinary = /usr/local/sbin/fping# 接下来启动[root@localhost smokeping]# bin/smokeping --logfile=/var/log/smokeping.logNote: logging to syslog as local0/info.Daemonizing bin/smokeping ...# 可以在日志里看到启动成功[root@localhost smokeping]# cat /var/log/smokeping.logSat Nov 16 21:23:13 2019 - Smokeping version 2.007003 successfully launched.Sat Nov 16 21:23:13 2019 - Not entering multiprocess mode for just a single probe.Sat Nov 16 21:23:13 2019 - FPing: probing 1 targets with step 60 s and offset 20 s.# 如果要停止smokeping进程[root@localhost smokeping]# ps -aux | grep smoke | grep -v greproot 34464 0.0 2.8 307688 28404 ? Ss 21:23 0:00 bin/smokeping [FPing][root@localhost smokeping]# ps -aux | grep smoke | grep -v grep | awk '{print $2}'34464# 然后使用kill -9 进程号 即可浏览器访问 http://192.168.99.101/smokeping 就需要输入刚才设置的帐密,也就是smokeping:smokeping
修改配置文件,在后面注释掉Test段落,添加自己的节点
[root@localhost smokeping]# vim /opt/smokeping/etc/config# 省略*** Targets ***probe = FPingmenu = Toptitle = Network Latency Grapherremark = Welcome to the SmokePing website of xxx Company. \Here you will learn all about the latency of our network.#+ Test#menu= Targets##parents = owner:/Test/James location:/#++ James#menu = James#title =James#alerts = someloss#slaves = boomer slave2#host = james.address#++ MultiHost#menu = Multihost#title = James and James as seen from Boomer#host = /Test/James /Test/James~boomer# 添加监测源的IP库,加入到config中,修改后重启smokeping才会生效# 添加监控节点示例:注意+是第一层,++是第二层,+++ 是第三层# 注释掉上面的,添加下面的监控节点+ NetMonitormenu = 三大网络监控title = 监控统计++ dianxinmenu = 电信网络监控title = 电信网络监控列表host = /NetMonitor/dianxin/dianxin-bj /NetMonitor/dianxin/dianxin-sc+++ dianxin-bjmenu = 北京电信title = 北京电信alerts = somelosshost = 202.96.199.133+++ dianxin-scmenu = 四川电信title = 四川电信alerts = somelosshost = 61.139.2.69++ liantongmenu = 联通网络监控title = 联通网络监控列表host = /NetMonitor/liantong/liantong-bj /NetMonitor/liantong/liantong-gz+++ liantong-bjmenu = 北京联通title = 北京联通alerts = somelosshost = 61.135.169.121+++ liantong-gzmenu = 广东联通title = 广东联通alerts = somelosshost = 221.5.88.88++ yidongmenu = 移动网络监控title = 移动网络监控列表host = /NetMonitor/yidong/yidong-sc /NetMonitor/yidong/yidong-gz+++ yidong-scmenu = 四川移动title = 四川移动alerts = somelosshost = 218.201.4.3+++ yidong-gzmenu = 广东移动title = 广东移动alerts = somelosshost = 211.136.192.6注意,在host中需要指定每一组节点信息例如host = /第一层/第二层/第三层,否则,浏览器访问指定该名称时会报错。添加监控节点后需要重启smokeping服务
[root@localhost smokeping]# systemctl restart smokeping但是报错啊,不过日志中这个WARNING不影响smokeping的正常运行。
[root@localhost ~]# tail -f /var/log/smokeping.log Sat Nov 16 22:50:36 2019 - FPing: WARNING: smokeping took 60.1801409721375 seconds to complete 1 round of polling. It should complete polling in 60 seconds. You may have unresponsive devices in your setup.主要是页面**问会提示创建目录失败,也就是无权限
Software error:ERROR: creating /opt/smokeping/cache/NetMonitor: No such file or directory解决办法是关闭Selinux
# 临时关闭[root@localhost smokeping]# getenforceEnforcing[root@localhost smokeping]# setenforce 0[root@localhost smokeping]# getenforcePermissive# 如果需要永久关闭 vim /etc/sysconfig/selinux ,SELINUX=enforcing 改为 SELINUX=disabled 然后重启蜜汁问题,smokeping终于正常创建目录了,绘图也正常了
绿色线绘出的是中间值(median)的位置,一个周期内探测返回的其它值都在中间值附近被以灰度的形式显示,灰度的范围越小说明此周期内抖动较小,灰度的颜色也有深浅,颜色越深,说明RTT值在此范围相对集中,灰**域如烟雾般笼罩在中间值附近,很契合smokeping的名称。
可以更改所有者(owner)、联系方式(contact)、邮件服务器(mailhost)、主站cgi地址(cgiurl,此选项对主从架构很重要)、syslog消息类型(syslogfacility)。同时,通过@include字段引用了同目录下的pathnames。
*** General ***owner = Peter Randomcontact = some@address.nowheremailhost = my.mail.hostsendmail = /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 = /opt/smokeping/cacheimgurl = cache# imgurl = http://192.168.99.101/cachedatadir = /opt/smokeping/datapiddir = /opt/smokeping/varcgiurl = http://192.168.99.101/smokeping.cgismokemail = /opt/smokeping/etc/smokemail.disttmail = /opt/smokeping/etc/tmail.dist# specify this to get syslog loggingsyslogfacility = local0# each probe is now run in its own process# disable this to revert to the old behaviour# concurrentprobes = no缺省条件下,采用sendmail邮件报警的方式,to 即接收方,from 即发送方。someloss是预定义的一个默认检测器,检测器不仅仅是一个阈值,它可以定义一组RTT从旧到新的变化过程,pattern 的值以一个运算符开始,按照从旧到新的状态变化,示例中,>0% 表示有丢包,*12* 表示在该组中最大忽略匹配12个数值,因此这段定义的意义是:匹配一组数据是否满足丢包次数大于等于3次。
*** Alerts ***to = alertee@address.somewherefrom = smokealert@company.xy+somelosstype = loss# in percentpattern = >0%,*12*,>0%,*12*,>0%comment = loss 3 times in a row描述rrd数据库的属性。
更改数据库配置文件无法对现有的rrd起作用,更改数据库配置文件后,需要清理现有的rrd缓存以使程序正常工作,默认rrd目录为:/opt/smokeping/data/,也就是自己配置的data目录。step 表示基本操作间隔,即smokeping探测目标主机的间隔,默认300秒,pings表示在一次探测动作中,发出探测包的数量,step 和 pings 的值均可以被后续的探针设置所覆盖。此配置也包含数据库归档合并的规则,共4列:合并方法、允许未知数值比例、步进,存储总行数。每一行表示一条RRA(循环归档)存储规则,预定义了多条AVERAGE、MIN,MAX规则。以AVERAGE为例,第一条AVERAGE,步进1,行数1008,按照缺省step=300的条件下,表示5分钟一条,最大1008条,共存储3.5天数据,这是以此精度绘图的最大时间范围,如果超出范围,将会继续匹配合适的RRA,比如第二条AVERAGE,存储的时间范围是180天,但是精度是1小时。
*** Database ***step = 60pings = 60# consfn mrhb steps totalAVERAGE 0.5 1 1008AVERAGE 0.5 12 4360MIN 0.5 12 4360MAX 0.5 12 4360AVERAGE 0.5 144 760MAX 0.5 144 760MIN 0.5 144 760template 即webUI使用的网页模板,默认指向/opt/smokeping/etc/basepage.html,模板中包含各种表单关键字。charset 即文档编码,默认使用UTF-8
*** Presentation ***charset = utf-8template = /opt/smokeping/etc/basepage.htmlhtmltitle = yesgraphborders = no+ chartsmenu = Chartstitle = The most interesting destinations++ stddevsorter = StdDev(entries=>4)title = Top Standard Deviationmenu = Std Deviationformat = Standard Deviation %f++ maxsorter = Max(entries=>5)title = Top Max Roundtrip Timemenu = by Maxformat = Max Roundtrip Time %f seconds++ losssorter = Loss(entries=>5)title = Top Packet Lossmenu = Lossformat = Packets Lost %f++ mediansorter = Median(entries=>5)title = Top Median Roundtrip Timemenu = by Medianformat = Median RTT %f seconds# smokeping支持报表功能,允许以特定的标准对图形目标排序显示。menu 表示菜单名称,title表示显示标题。# 在子配置项中,可以看到sorter选项,通过此选项可以制定排序器,针对RTT的统计,# 内置了:标准差 StdDev(arg1=>val1,arg2=>val2),最大 Max(arg1=>val1,arg2=>val2),丢包率 Loss(arg1=>val1,arg2=>val2)等排序方法。# format选项表示图例输出格式,此格式参考fprint字符串格式。+ overview width = 600height = 200range = 10h# overview 部分,定义了概述图的外观,宽 width,高 height,# 时间跨度 range,range的格式可以是s(seconds), m(minutes), h(hours), d(days), w(weeks), y(years)。+ detailwidth = 600height = 600unison_tolerance = 2# detail部分定义了详细图的外观,宽 width,高 height,unison_tolerance 规定了统一缩放的因子,# 此值必须参照每轮探测RTT结果的max中间值即median max,实际是为了保证图形缩放时的可读性,默认值为2,# 表示任何最大值小于中间值“max”一半或两倍以上的图都将从统一缩放中删除。"Last 3 Hours" 3h"Last 30 Hours" 30h"Last 10 Days" 10d"Last 400 Days" 400d# detail 也包含可定义图形时间尺度的部分,包含两列:图形时间尺度的描述和时间跨度值,此值的格式与overview部分的range格式一致。#+ hierarchies#++ owner#title = Host Owner#++ location#title = Locationsmokeping支持很多探针模块,最常用的就是内联的fping。
*** Probes ***+ FPing# binary = /usr/sbin/fpingbinary = /usr/local/sbin/fping在使用主从结构时,需要一个验证文件,即secrets指定的值,默认为 /opt/smokeping/etc/smokeping_secrets,对于每一个从节点,还需要指定显示名称 display_name,显示颜色 color(此颜色指的是概述图上的线色,非细节图),颜色代码采用RRGGBB形式。
*** Slaves ***secrets=/opt/smokeping/etc/smokeping_secrets+boomerdisplay_name=boomercolor=0000ff+slave2display_name=anothercolor=00ff00Target是搭建snokeping主要配置的部分。menu定义了条目的菜单名称,title定义了条目的标题名称,host 定义了目标主机名,alerts定义了使用的报警器,probe定义了使用的探针,slaves定义了需要使用的从服务器列表。同样,子条目的参数会继承父条目,也可以进行覆盖。
*** Targets ***probe = FPingmenu = Toptitle = Network Latency Grapherremark = Welcome to the SmokePing website of xxx Company. \Here you will learn all about the latency of our network.#+ Test#menu= Targets##parents = owner:/Test/James location:/#++ James#menu = James#title =James#alerts = someloss#slaves = boomer slave2#host = james.address#++ MultiHost#menu = Multihost#title = James and James as seen from Boomer#host = /Test/James /Test/James~boomer+ NetMonitormenu = 三大网络监控title = 监控统计++ dianxinmenu = 电信网络监控title = 电信网络监控列表host = /NetMonitor/dianxin/dianxin-bj /NetMonitor/dianxin/dianxin-sc+++ dianxin-bjmenu = 北京电信title = 北京电信alerts = somelosshost = 202.96.199.133+++ dianxin-scmenu = 四川电信title = 四川电信alerts = somelosshost = 61.139.2.69++ liantongmenu = 联通网络监控title = 联通网络监控列表host = /NetMonitor/liantong/liantong-bj /NetMonitor/liantong/liantong-gz+++ liantong-bjmenu = 北京联通title = 北京联通alerts = somelosshost = 61.135.169.121+++ liantong-gzmenu = 广东联通title = 广东联通alerts = somelosshost = 221.5.88.88++ yidongmenu = 移动网络监控title = 移动网络监控列表host = /NetMonitor/yidong/yidong-sc /NetMonitor/yidong/yidong-gz+++ yidong-scmenu = 四川移动title = 四川移动alerts = somelosshost = 218.201.4.3+++ yidong-gzmenu = 广东移动title = 广东移动alerts = somelosshost = 211.136.192.6可以将监控的节点独立出来,然后使用@include xxx指定这个文件即可。也就是可以不用在config配置文件中加上监控IP的配置,直接独立出来即可。
在config同一目录下创建一个文件
[root@localhost smokeping]# vim etc/net_test.list# 添加+ NetMonitor_testmenu = 三大网络监控_includetitle = 监控统计++ dianxinmenu = 电信网络监控title = 电信网络监控列表host = /NetMonitor_test/dianxin/dianxin-bj /NetMonitor_test/dianxin/dianxin-sc+++ dianxin-bjmenu = 北京电信title = 北京电信alerts = somelosshost = 202.96.199.133+++ dianxin-scmenu = 四川电信title = 四川电信alerts = somelosshost = 61.139.2.69++ liantongmenu = 联通网络监控title = 联通网络监控列表host = /NetMonitor_test/liantong/liantong-bj /NetMonitor_test/liantong/liantong-gz+++ liantong-bjmenu = 北京联通title = 北京联通alerts = somelosshost = 61.135.169.121+++ liantong-gzmenu = 广东联通title = 广东联通alerts = somelosshost = 221.5.88.88++ yidongmenu = 移动网络监控title = 移动网络监控列表host = /NetMonitor_test/yidong/yidong-sc /NetMonitor_test/yidong/yidong-gz+++ yidong-scmenu = 四川移动title = 四川移动alerts = somelosshost = 218.201.4.3+++ yidong-gzmenu = 广东移动title = 广东移动alerts = somelosshost = 211.136.192.6修改smokeping的配置文件,在最后引入这个配置
[root@localhost smokeping]# vim etc/config# 最后添加@include net_test.list[root@localhost smokeping]# systemctl restart smokeping现在就增加了另一项。