借助claude写了个监控VPS流量使用的脚本,调试了大概三四天,今天终于是完全体了!github项目地址:https://github.com/ypq123456789/TrafficCop 喜欢这个项目的可以给个star!
# TrafficCop - 智能流量监控与限制脚本
## 特别提醒**流量统计是从你开始安装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共享带宽试了下,精度还是比较高的!
求个点赞不过分吧家人们!真的调试了很久!有bug可以提isuue或者pr,我这个小菜鸡尽量修复
看不懂 牛逼
我看不懂,但我大受震撼~
人皇 看不懂 牛逼
谢谢大佬支持,可以测试使用下哈,另外咱论坛发帖是不支持markdown语法吗,那么大佬们都是怎么排版的呢
dami 我看不懂,但我大受震撼~
我试试看这个格式是否可行:
[size=5][b]TrafficCop - 智能流量监控与限制脚本[/b][/size]
[size=4][b]特别提醒[/b][/size]
[b]流量统计是从你开始安装vnstat开始的[/b]
[b]如果你在安装本脚本之前没有安装过vnstat,请注意:本脚本基于vnstat的流量统计,而vnstat只会从它安装好之后开始统计流量![/b]
[size=4][b]一键安装脚本[/b][/size]
[size=3][b]标准安装(可能有几分钟延迟):[/b][/size]
[code]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[/code]
[size=3][b]快速更新版本:[/b][/size]
[code]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[/code]
[size=4][b]实用命令[/b][/size]
[size=3][b]查看日志:[/b][/size]
[code]tail -f -n 30 /root/traffic_monitor.log[/code]
[size=3][b]查看当前配置:[/b][/size]
[code]cat traffic_monitor_config.txt[/code]
[size=3][b]紧急停止所有traffic_monitor进程(用于脚本出现问题时):[/b][/size]
[code]pkill -f traffic_monitor.sh[/code]
[size=3][b]一键解除限速[/b][/size]
[code]curl -sSL https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/remove_traffic_limit.sh | sudo bash[/code]
[size=4][b]脚本逻辑[/b][/size]
- 自动检测并选择主要网卡进行流量限制。
- 用户选择流量统计模式(四种选项)。
- 用户设置流量计算周期(月/季/年)和起始日期。
- 用户输入流量限制和容错范围。
- 用户选择限制模式(TC模式或关机模式)。
- 对于TC模式,用户可设置限速值。
- 脚本每分钟检测流量消耗,达到限制时执行相应操作。
- 在新的流量周期开始时自动解除限制。
[size=4][b]脚本特色[/b][/size]
- 四种全面的流量统计模式,适应各种VPS计费方式。
- 自定义流量计算周期和起始日。
- 自定义流量容错范围。
- 交互式配置,可随时修改参数。
- 实时流量统计提示。
- TC模式保证SSH连接可用。
- 关机模式提供更严格的流量控制。
- 自定义限速带宽(TC模式)。
[size=4][b]预设配置[/b][/size]
[size=3][b]阿里云CDT 200G:[/b][/size]
[code]curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-200g[/code]
[size=3][b]阿里云CDT 20G:[/b][/size]
[code]curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-20g[/code]
我拿阿里云香港cdt共享带宽试了下,精度还是比较高的!如下图所示
[img]https://i.111666.best/image/5vG2f6ePePhAi5CFMeXyLJ.png[/img]
[img]https://i.111666.best/image/8oHIzD80EpG2GnxHtsFvem.png[/img]
tinymce格式是这样吗,看看显示效果:
<h2>TrafficCop - 智能流量监控与限制脚本</h2>
<h3>特别提醒</h3><p><strong>流量统计是从你开始安装vnstat开始的</strong></p>
<p><strong>流量统计是从你开始安装vnstat开始的</strong></p>
<p><strong>如果你在安装本脚本之前没有安装过vnstat,请注意:本脚本基于vnstat的流量统计,而vnstat只会从它安装好之后开始统计流量!</strong></p>
<h3>一键安装脚本</h3>
<h4>标准安装(可能有几分钟延迟):</h4><pre><code>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</code></pre>
<h4>快速更新版本:</h4><pre><code>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</code></pre>
<h3>实用命令</h3><h4>查看日志:</h4><pre><code>tail -f -n 30 /root/traffic_monitor.log</code></pre>
<h4>查看当前配置:</h4><pre><code>cat traffic_monitor_config.txt</code></pre>
<h4>紧急停止所有traffic_monitor进程(用于脚本出现问题时):</h4><pre><code>pkill -f traffic_monitor.sh</code></pre>
<h4>一键解除限速</h4><pre><code>curl -sSL https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/remove_traffic_limit.sh | sudo bash</code></pre>
<h3>脚本逻辑</h3><ul><li>自动检测并选择主要网卡进行流量限制。</li><li>用户选择流量统计模式(四种选项)。</li><li>用户设置流量计算周期(月/季/年)和起始日期。</li><li>用户输入流量限制和容错范围。</li><li>用户选择限制模式(TC模式或关机模式)。</li><li>对于TC模式,用户可设置限速值。</li><li>脚本每分钟检测流量消耗,达到限制时执行相应操作。</li><li>在新的流量周期开始时自动解除限制。</li></ul>
<h3>脚本特色</h3><ul><li>四种全面的流量统计模式,适应各种VPS计费方式。</li><li>自定义流量计算周期和起始日。</li><li>自定义流量容错范围。</li><li>交互式配置,可随时修改参数。</li><li>实时流量统计提示。</li><li>TC模式保证SSH连接可用。</li><li>关机模式提供更严格的流量控制。</li><li>自定义限速带宽(TC模式)。</li></ul>
<h3>预设配置</h3><h4>阿里云CDT 200G:</h4><pre><code>curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-200g</code></pre>
<h4>阿里云CDT 20G:</h4><pre><code>curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-20g</code></pre>
<p>我拿阿里云香港cdt共享带宽试了下,精度还是比较高的!如下图所示</p><img src="https://i.111666.best/image/5vG2f6ePePhAi5CFMeXyLJ.png" alt="阿里云CDT测试结果1" /><img src="https://i.111666.best/image/8oHIzD80EpG2GnxHtsFvem.png" alt="阿里云CDT测试结果2" />
<p>求个点赞不过分吧家人们