跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[VPS] [TrafficCop] 监控 VPS 流量使用,到达限制自动限流,保留 SSH 端口可用

发表于

借助 claude 写了个监控 VPS 流量使用的脚本,调试了大概三四天,今天终于是完全体了! github 项目地址: https://github.com/ypq123456789/TrafficCop 喜欢这个项目的可以给个 star !

TrafficCop - 智能流量监控与限制脚本

特别提醒

流量统计是从你开始安装 vnstat 开始的

流量统计是从你开始安装 vnstat 开始的

流量统计是从你开始安装 vnstat 开始的

如果你在安装本脚本之前没有安装过 vnstat ,请注意:本脚本基于 vnstat 的流量统计,而 vnstat 只会从它安装好之后开始统计流量!

一键安装脚本

标准安装(可能有几分钟延迟):

curl -fsSL https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/trafficcop.sh -o /root/traffic_monitor.sh && chmod +x /root/traffic_monitor.sh && bash /root/traffic_monitor.sh

快速更新版本:

curl -H "Accept: application/vnd.github.v3.raw" -fsSL "https://api.github.com/repos/ypq123456789/TrafficCop/contents/trafficcop.sh" | tr -d '\r' > /root/traffic_monitor.sh && chmod +x /root/traffic_monitor.sh && bash /root/traffic_monitor.sh

实用命令

查看日志:

tail -f -n 30 /root/traffic_monitor.log

查看当前配置:

cat traffic_monitor_config.txt

紧急停止所有 traffic_monitor 进程(用于脚本出现问题时):

pkill -f traffic_monitor.sh

一键解除限速

curl -sSL https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/remove_traffic_limit.sh | sudo bash

脚本逻辑

  • 自动检测并选择主要网卡进行流量限制。
  • 用户选择流量统计模式(四种选项)。
  • 用户设置流量计算周期(月/季/年)和起始日期。
  • 用户输入流量限制和容错范围。
  • 用户选择限制模式( TC 模式或关机模式)。
  • 对于 TC 模式,用户可设置限速值。
  • 脚本每分钟检测流量消耗,达到限制时执行相应操作。
  • 在新的流量周期开始时自动解除限制。

脚本特色

  • 四种全面的流量统计模式,适应各种 VPS 计费方式。
  • 自定义流量计算周期和起始日。
  • 自定义流量容错范围。
  • 交互式配置,可随时修改参数。
  • 实时流量统计提示。
  • TC 模式保证 SSH 连接可用。
  • 关机模式提供更严格的流量控制。
  • 自定义限速带宽( TC 模式)。

预设配置

阿里云 CDT 200G:

curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-200g

阿里云 CDT 20G:

curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-20g

我拿阿里云香港 cdt 共享带宽试了下,精度还是比较高的!如下图所示 5vG2f6ePePhAi5CFMeXyLJ 8oHIzD80EpG2GnxHtsFvem

求个点赞不过分吧家人们!真的调试了很久!有 bug 可以提 isuue 或者 pr ,我这个小菜鸡尽量修复

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.