Mark's blog 这是 Mark 的个人博客,记录些东西。

Rust 版 ServerStatus 云探针

效果: ServerStatus

源码: Github

服务端:

https://github.com/zdz/ServerStatus-Rust/wiki/Railway

客户端:

mkdir -p /opt/ServerStatus && cd /opt/ServerStatus
wget --no-check-certificate -qO ServerStatus-x86_64-unknown-linux-musl.zip  "https://github.com/zdz/ServerStatus-Rust/releases/download/v1.3.4/ServerStatus-x86_64-unknown-linux-musl.zip"
unzip -o ServerStatus-x86_64-unknown-linux-musl.zip
chmod +x stat_client

编辑 stat\_client.service

ExecStart=/opt/ServerStatus/stat_client -a "https://serverstatus-rust-production-fdd1.up.railway.app/report" -u h1 -p p1
mv -v stat_client.service /etc/systemd/system/stat_client.service
systemctl daemon-reload

# 启动
systemctl start stat_client

# 状态查看
systemctl status stat_client

# 使用以下命令开机自启
systemctl enable stat_client

# 停止
systemctl stop stat_client

开启 vnstat 支持

vnstat 是Linux下一个流量统计工具,开启 vnstat 后,server 完全依赖客户机的 vnstat 数据来显示月流量和总流量,优点是重启不丢流量数据。

安装版本必须 > 2.6 !!! 安装参考:https://009898.xyz/post/vnstat-liu-liang-tong-ji-28-ban-ben/

# 修改 /etc/vnstat.conf
# BandwidthDetection 0
# MaxBandwidth 0
# 默认不是 eth0 网口的需要置空 Interface 来自动选择网口
# 没报错一般不需要改
# Interface ""
systemctl restart vnstat

# 确保 version >= 2.6
vnstat --version
# 测试查看月流量 (刚安装可能需等一小段时间来采集数据)
vnstat -m
vnstat --json m

# server config.toml 开启 vnstat
vnstat = true

# client 使用 -n 参数开启 vnstat 统计
./stat_client -a "tcp://127.0.0.1:34512" -u h1 -p p1 -n
# 或
python3 client-linux.py -a "http://127.0.0.1:8080/report" -u h1 -p p1 -n
By Mark On