网络性能监控工具Smokeping
Jan. 22, 2022
Smokeping 是开源免费的网络性能监控工具。
SmokePing 是一款监控网络状态和稳定性的开源软件(它是 RRDTool 的作者开发的),通过它可以监控如延时,丢包率,是否 BGP 多线等网络状况;smokeping 会向目标设备和系统发送各种类型的测试数据包,测量、记录,并通过图形化地展示网络的时延情况,进而能够清楚的判断出网络的即时通信情况;
可以用于监控群晖主机的网络状态,也可以用于监控多台 vps 的运行状态,支持通过邮件报警。
安装 在群晖上以 Docker 方式安装。
在注册表中搜索 smokeping ,选择第一个 linuxserver/smokeping,版本选择 latest。
卷 在 docker 文件夹中,创建一个新文件夹,并将其命名为 smokeping,并在 smokeping 中建两个子目录,分别命名为 config 和 data。
文件夹 装载路径 备注 /docker/smokeping/data /data 数据库和应用数据目录 /docker/smokeping/config /config 配置文件目录
端口 端口不能冲突
本地端口 容器端口 类型 8580 80 TCP
环境 可变 值 TZ 设置为 Asia/Shanghai PGID <gid> 设为 1000 PUID <uid> 设为 1000
运行 在浏览器中输入 http://群晖IP:8580,就能看到主界面了
配置文件 配置文件在 /docker/smokeping/config 目录中,知道了用途可以方便后面的修改
文件 用途 Alerts 报警设置 Database 采样频率设置 General 常规设置 httpd.conf Apache Web 服务器设置 pathnames 路径设置 Presentation 模板文件 Probes 探针设置 Slaves 主从模式时,从机设置 ssmtp.conf 邮件服务器设置 Targets 监控目标设置
Database 打开 smokeping/config/Database 文件,全部采用了默认值,也就是 300 秒(5 分钟)ping 20 次
Probes 编辑 smokeping/config/Probes 文件,将 dns 中的 google.com 改为了 baidu.com,其他都是默认的
邮件报警 第一步、编辑 ssmtp.conf
配置生效需要重启容器
除了密码都在下面👇
Debug=YES
Config file for sSMTP sendmail
The person who gets all mail for userids < 1000
Make this empty to disable rewriting.
root=wbsu2003@88.com
The place where the mail goes. The actual machine name is required no
MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.88.com:465 AuthUser=wbsu2003@88.com AuthPass=88邮箱设置的专用密码 UseSTARTTLS=NO
UseTLS=YES
Where will the mail seem to come from?
rewriteDomain=88.com
The full hostname
hostname=linuxserver-smokeping1
Are users allowed to set their own From: address?
YES - Allow the user to specify their own From: address
NO - Use the system generated From: address
FromLineOverride=YES 老苏用的是 88 邮箱,相关参数可以在 设置 中找到
设置完成后,可以通过 『终端机』 进入容器内进行 Email 发送调试,命令行下输入 ssmtp -v wbsu2003@hotmail.com ,再依次输入:
To: wbsu2003@hotmail.com From: wbsu2003@88.com Subject: alert <回车2次>
test123 <ctrl+D>
去收件箱查看邮件
第二步、编辑 Alerts
修改红框部分
to:接收报警的邮箱,也可以是自定义脚本; from:发送报警信息的邮箱,也就是上一步在 ssmtp.conf 中设置的邮箱; 下面是报警触发的条件
设的比较低是想更容易触发报警,实际应用延时可以设在 200ms
*** Alerts *** to = wbsu2003@hotmail.com from = wbsu2003@88.com
+rttdetect type = rtt pattern = <20,<20,<20,<20,<20,>20,>20,>20 comment = 连续3次延时20以上
+lossdetect type = loss pattern = ==0%,==0%,==0%,==0%,==0%,>0%,>0%,>0% comment = 突然有丢包
Targets Internet Sites 基本上是我们正常无法访问的站点,所以需要进行修改,不然会没有数据
编辑 smokeping/config/Targets 文件
编辑之前请先做好备份
格式一目了然,采用了是分层结构,用+表示,例如第一层“+”,第二层“++”一次类推可以增加也可以修改
下面👇这段来自 https://wzfou.com/smokeping/,但根据我们前面设置的 Probes 和 Alerts进行了微调
- Other menu = 三大网络监控 title = 监控统计 probe = FPing
++ dianxin menu = 电信网络监控 title = 电信网络监控列表 host = /Other/dianxin/dianxin-bj /Other/dianxin/dianxin-hlj /Other/dianxin/dianxin-tj /Other/dianxin/dianxin-sc /Other/dianxin/dianxin-sh /Other/dianxin/dianxin-gz
+++ dianxin-bj menu = 北京电信 title = 北京电信 host = 202.96.199.133 alerts = rttdetect,lossdetect
+++ dianxin-hlj menu = 黑龙江电信 title = 黑龙江电信 host = 219.147.198.242 alerts = rttdetect,lossdetect
+++ dianxin-tj menu = 天津电信 title = 天津电信 host = 219.150.32.132 alerts = rttdetect,lossdetect
+++ dianxin-sc menu = 四川电信 title = 四川电信 host = 61.139.2.69 alerts = rttdetect,lossdetect
+++ dianxin-sh menu = 上海电信 title = 上海电信 host = 116.228.111.118 alerts = rttdetect,lossdetect
+++ dianxin-gz menu = 广东电信 title = 广东电信 host = 113.111.211.22 alerts = rttdetect,lossdetect
++ liantong menu = 联通网络监控 title = 联通网络监控列表 host = /Other/liantong/liantong-bj /Other/liantong/liantong-hlj /Other/liantong/liantong-tj /Other/liantong/liantong-sc /Other/liantong/liantong-sh /Other/liantong/liantong-gz
+++ liantong-bj menu = 北京联通 title = 北京联通 host = 61.135.169.121 alerts = rttdetect,lossdetect
+++ liantong-hlj menu = 黑龙江联通 title = 黑龙江联通 host = 202.97.224.69 alerts = rttdetect,lossdetect
+++ liantong-tj menu = 天津联通 title = 天津联通 host = 202.99.96.68 alerts = rttdetect,lossdetect
+++ liantong-sc menu = 四川联通 title = 四川联通 host = 119.6.6.6 alerts = rttdetect,lossdetect
+++ liantong-sh menu = 上海联通 title = 上海联通 host = 210.22.84.3 alerts = rttdetect,lossdetect
+++ liantong-gz menu = 广东联通 title = 广东联通 host = 221.5.88.88 alerts = rttdetect,lossdetect
++ yidong menu = 移动网络监控 title = 移动网络监控列表 host = /Other/yidong/yidong-bj /Other/yidong/yidong-hlj /Other/yidong/yidong-tj /Other/yidong/yidong-sc /Other/yidong/yidong-sh /Other/yidong/yidong-gz
+++ yidong-bj menu = 北京移动 title = 北京移动 host = 221.130.33.52 alerts = rttdetect,lossdetect
+++ yidong-hlj menu = 黑龙江移动 title = 黑龙江移动 host = 211.137.241.35 alerts = rttdetect,lossdetect
+++ yidong-tj menu = 天津移动 title = 天津移动 host = 211.137.160.5 alerts = rttdetect,lossdetect
+++ yidong-sc menu = 四川移动 title = 四川移动 host = 218.201.4.3 alerts = rttdetect,lossdetect
+++ yidong-sh menu = 上海移动 title = 上海移动 host = 117.131.19.23 alerts = rttdetect,lossdetect
+++ yidong-gz menu = 广东移动 title = 广东移动 host = 211.136.192.6 alerts = rttdetect,lossdetect 因为有中文,要使用 utf-8 格式
配置生效需要重启容器
如果是用默认的 GB18030 编码保存,中文会乱码
而正常显示应该是这样的
随着时间的推移,逐步会产生数据
当触发了设定的延迟( rttdetect )或者丢包( lossdetect )条件时,会收到邮件提醒
而如果邮件设置有问题,会在 config 目录中生成 dead.letter 文件,用于记录触发过的报警
下载之后打开文件内容是下面👇这样的
参考文档 oetiker/SmokePing: The Active Monitoring System 地址:https://github.com/oetiker/SmokePing
SmokePing - About SmokePing 地址:https://oss.oetiker.ch/smokeping/
How to install SmokePing – sleeplessbeastie’s notes 地址:https://sleeplessbeastie.eu/2020/06/19/how-to-install-smokeping/
Smokeping安装与配置-免费开源网络性能监控工具可视化主/从部署 - 挖站否-挖掘建站的乐趣 地址:https://wzfou.com/smokeping/
ssmtp-命令行发送邮件 | Hom 地址:https://gohom.win/2016/10/07/ssmtp/