借助claude写了个监控VPS流量使用的脚本,调试了大概三四天,今天终于是完全体了!
github项目地址:GitHub - ypq123456789/TrafficCop: 监控VPS流量使用,到达限制自动限流/关机,保留SSH端口可用 · GitHub 喜欢这个项目的可以给个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
```
## 脚本逻辑
## 脚本特色
## 预设配置
### 阿里云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,我这个小菜鸡尽量修复
