| Crates.io | swb-sys-monitor |
| lib.rs | swb-sys-monitor |
| version | 0.6.0 |
| created_at | 2025-10-09 15:57:26.463295+00 |
| updated_at | 2025-12-16 07:19:52.410832+00 |
| description | 为嵌入式设备高并发监控场景设计的极简网页资源占用显示系统 |
| homepage | https://github.com/swaybien/swb-sys-monitor |
| repository | https://github.com/swaybien/swb-sys-monitor |
| max_upload_size | |
| id | 1875814 |
| size | 233,498 |
English | 简体中文
一个极简的资源占用显示系统,专为嵌入式设备高并发监控场景设计。支持 200+ 高并发客户端访问,采用无锁算法实现高性能。
cargo install swb-sys-monitor
# 克隆仓库
git clone https://github.com/swaybien/swb-sys-monitor.git
cd swb-sys-monitor
# 构建发布版本
cargo build --release
# 或者直接运行
cargo run -- --help
# 使用默认配置启动(监听 [::]:8080,缓存 TTL 10 秒)
./target/release/swb-sys-monitor
# 自定义配置
./target/release/swb-sys-monitor --address 127.0.0.1 --port 3000 --ttl 5
# 设置日志级别
./target/release/swb-sys-monitor --log-level debug
启动后,在浏览器中访问 http://localhost:8080 即可查看系统资源占用情况。
页面会每 10 秒自动刷新,显示以下信息:
系统提供健康检查端点 http://localhost:8080/health,用于监控服务状态:
curl http://localhost:8080/health
# 返回: OK
| 参数 | 短参数 | 默认值 | 描述 |
|---|---|---|---|
--address |
-a |
:: |
服务器绑定地址(支持 IPv4 和 IPv6) |
--port |
-p |
8080 |
服务器端口 |
--ttl |
-t |
10 |
缓存 TTL 秒数 |
--log-level |
-l |
info |
日志级别 (trace, debug, info, warn, error) |
--help |
-h |
- | 显示帮助信息 |
/proc/stat 和 /proc/meminfo 获取系统信息AtomicPtr 和 AtomicU64 实现线程安全缓存String::with_capacity 预分配容量,减少重新分配#[inline] 属性优化性能# 编译检查
cargo check --all-targets
# 代码规范检查
cargo clippy
# 运行测试
cargo test
# 运行基准测试
cargo bench
# 构建发布版本
cargo build --release
项目包含全面的测试覆盖:
使用提供的安装脚本自动部署到 systemd 系统:
# 克隆仓库
git clone https://github.com/swaybien/swb-sys-monitor.git
cd swb-sys-monitor
# 运行安装脚本
sudo ./scripts/install.sh
# 如需卸载
sudo ./scripts/uninstall.sh
详细的部署脚本使用说明请参考 部署指南。
创建 systemd 服务文件 /etc/systemd/system/swb-sys-monitor.service:
[Unit]
Description=Resource Status Monitor
After=network.target
[Service]
Type=simple
User=nobody
ExecStart=/usr/local/bin/swb-sys-monitor
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
启用和启动服务:
sudo systemctl enable swb-sys-monitor
sudo systemctl start swb-sys-monitor
# 克隆仓库
git clone https://github.com/swaybien/swb-sys-monitor.git
cd swb-sys-monitor
# 启动服务
docker-compose up -d
# 查看日志
docker-compose logs -f swb-sys-monitor
# 停止服务
docker-compose down
# 构建镜像
docker build -t swb-sys-monitor .
# 运行容器
docker run -d \
--name swb-sys-monitor \
--restart unless-stopped \
-p 18273:8080 \
--read-only \
--tmpfs /tmp \
--cap-drop ALL \
--cap-add DAC_OVERRIDE \
--security-opt no-new-privileges:true \
swb-sys-monitor
# 查看日志
docker logs -f swb-sys-monitor
# 停止容器
docker stop swb-sys-monitor
docker rm swb-sys-monitor
Docker 部署包含以下安全特性:
no-new-privileges 防止权限提升可以通过环境变量自定义配置:
# docker-compose.yml
services:
swb-sys-monitor:
build: .
environment:
- RUST_LOG=debug
command:
[
"./swb-sys-monitor",
"--address",
"0.0.0.0",
"--port",
"8080",
"--ttl",
"5",
]
本项目采用 MIT 许可证。详见 LICENSE 文件。
欢迎提交 Issue 和 Pull Request! 请阅读贡献指北。