更新重试器
This commit is contained in:
111
Cargo.lock
generated
111
Cargo.lock
generated
@ -466,6 +466,21 @@ version = "1.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
|
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.32"
|
version = "0.3.32"
|
||||||
@ -473,6 +488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
|
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -481,6 +497,34 @@ version = "0.3.32"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
|
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-executor"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.32"
|
version = "0.3.32"
|
||||||
@ -499,8 +543,13 @@ version = "0.3.32"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"slab",
|
"slab",
|
||||||
]
|
]
|
||||||
@ -1180,13 +1229,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pt_system_checking"
|
name = "pt_system_checking"
|
||||||
version = "0.1.5"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"config",
|
"config",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"reqwest-middleware",
|
||||||
|
"reqwest-retry",
|
||||||
"serde",
|
"serde",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -1358,6 +1409,50 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "reqwest-middleware"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "199dda04a536b532d0cc04d7979e39b1c763ea749bf91507017069c00b96056f"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
|
"http",
|
||||||
|
"reqwest",
|
||||||
|
"thiserror 2.0.18",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "reqwest-retry"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fe2412db2af7d2268e7a5406be0431f37d9eb67ff390f35b395716f5f06c2eaa"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
|
"futures",
|
||||||
|
"getrandom 0.2.17",
|
||||||
|
"http",
|
||||||
|
"hyper",
|
||||||
|
"reqwest",
|
||||||
|
"reqwest-middleware",
|
||||||
|
"retry-policies",
|
||||||
|
"thiserror 2.0.18",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
"wasmtimer",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "retry-policies"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "46a4bd6027df676bcb752d3724db0ea3c0c5fc1dd0376fec51ac7dcaf9cc69be"
|
||||||
|
dependencies = [
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ring"
|
name = "ring"
|
||||||
version = "0.17.14"
|
version = "0.17.14"
|
||||||
@ -2177,6 +2272,20 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasmtimer"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1c598d6b99ea013e35844697fc4670d08339d5cda15588f193c6beedd12f644b"
|
||||||
|
dependencies = [
|
||||||
|
"futures",
|
||||||
|
"js-sys",
|
||||||
|
"parking_lot",
|
||||||
|
"pin-utils",
|
||||||
|
"slab",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.88"
|
version = "0.3.88"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pt_system_checking"
|
name = "pt_system_checking"
|
||||||
version = "0.1.5"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -9,6 +9,8 @@ chrono = "0.4.43"
|
|||||||
clap = { version = "4.5.60", features = ["derive"] }
|
clap = { version = "4.5.60", features = ["derive"] }
|
||||||
config = "0.15.19"
|
config = "0.15.19"
|
||||||
reqwest = "0.13.2"
|
reqwest = "0.13.2"
|
||||||
|
reqwest-middleware = "0.5.1"
|
||||||
|
reqwest-retry = "0.9.1"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
sysinfo = "0.38.2"
|
sysinfo = "0.38.2"
|
||||||
tokio = { version = "1.49.0", features = ["full"] }
|
tokio = { version = "1.49.0", features = ["full"] }
|
||||||
|
|||||||
40
README.md
40
README.md
@ -1,26 +1,12 @@
|
|||||||
# PT System Checking - 磁盘状态监控服务
|
# PT System Checking
|
||||||
|
|
||||||
一个轻量级的系统磁盘监控服务,定期检查磁盘可用空间并上报到指定服务器。
|
上报硬盘剩余空间到 Uptime Kuma 实例,以 ping 作为空间剩余
|
||||||
|
|
||||||
## 功能特性
|
## 部署
|
||||||
|
|
||||||
- 自动检测所有非可移动磁盘的可用空间
|
|
||||||
- 定期上报磁盘状态到远程服务器
|
|
||||||
- 支持通过环境变量或命令行参数配置
|
|
||||||
- 支持 amd64 和 arm64 架构(适用于香橙派 Zero3)
|
|
||||||
- 一键部署脚本,自动配置 systemd 服务
|
|
||||||
|
|
||||||
## 快速开始
|
|
||||||
|
|
||||||
### 一键部署(推荐)
|
### 一键部署(推荐)
|
||||||
|
|
||||||
在目标设备上运行以下命令:
|
下载后运行(因为需要交互脚本):
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -fsSL https://gitea.service.jazzwhom.top/Passthem/pt-disk-report/raw/branch/main/install.sh | sudo bash
|
|
||||||
```
|
|
||||||
|
|
||||||
或者下载后运行:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://gitea.service.jazzwhom.top/Passthem/pt-disk-report/raw/branch/main/install.sh
|
wget https://gitea.service.jazzwhom.top/Passthem/pt-disk-report/raw/branch/main/install.sh
|
||||||
@ -46,20 +32,13 @@ wget https://gitea.service.jazzwhom.top/Passthem/pt-disk-report/raw/branch/main/
|
|||||||
sudo bash update.sh
|
sudo bash update.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
更新脚本会:
|
|
||||||
1. 检查当前安装的版本
|
|
||||||
2. 获取最新版本信息
|
|
||||||
3. 自动备份当前版本
|
|
||||||
4. 下载并替换新版本
|
|
||||||
5. 重启服务(如果更新失败会自动恢复备份)
|
|
||||||
|
|
||||||
### 卸载服务
|
### 卸载服务
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo bash install.sh uninstall
|
sudo bash install.sh uninstall
|
||||||
```
|
```
|
||||||
|
|
||||||
## 本地构建
|
## 本地构建与发布
|
||||||
|
|
||||||
### 安装交叉编译工具链
|
### 安装交叉编译工具链
|
||||||
|
|
||||||
@ -85,6 +64,12 @@ make prepare-release
|
|||||||
- `install.sh` - 一键部署脚本
|
- `install.sh` - 一键部署脚本
|
||||||
- `update.sh` - 一键更新脚本
|
- `update.sh` - 一键更新脚本
|
||||||
|
|
||||||
|
### 发布 Gitea Release
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make create-release VERSION=0.1.5
|
||||||
|
```
|
||||||
|
|
||||||
## 配置说明
|
## 配置说明
|
||||||
|
|
||||||
服务支持以下配置项(通过环境变量):
|
服务支持以下配置项(通过环境变量):
|
||||||
@ -141,6 +126,3 @@ make test
|
|||||||
make clean
|
make clean
|
||||||
```
|
```
|
||||||
|
|
||||||
## 许可证
|
|
||||||
|
|
||||||
根据项目需要添加许可证信息。
|
|
||||||
|
|||||||
13
src/main.rs
13
src/main.rs
@ -2,6 +2,8 @@ use std::{collections::HashSet, time::Duration};
|
|||||||
|
|
||||||
use clap::{Parser};
|
use clap::{Parser};
|
||||||
use config::{Config, ConfigError, Environment};
|
use config::{Config, ConfigError, Environment};
|
||||||
|
use reqwest_middleware::ClientBuilder;
|
||||||
|
use reqwest_retry::{RetryTransientMiddleware, policies::ExponentialBackoff};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tokio::time::interval;
|
use tokio::time::interval;
|
||||||
|
|
||||||
@ -59,8 +61,8 @@ async fn task(settings: &Settings) -> anyhow::Result<()> {
|
|||||||
available += davailable;
|
available += davailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
let report = ((available >> 20) * 10) >> 10;
|
let report = ((available >> 20) * 100) >> 10;
|
||||||
tracing::info!(report = report, "获取剩余硬盘空间(单位 .1GB)");
|
tracing::info!(report = report, "获取剩余硬盘空间(单位 .01GB)");
|
||||||
|
|
||||||
if settings.server_url.is_empty() {
|
if settings.server_url.is_empty() {
|
||||||
tracing::warn!("没有配置服务器地址,不会上报给服务端");
|
tracing::warn!("没有配置服务器地址,不会上报给服务端");
|
||||||
@ -72,9 +74,14 @@ async fn task(settings: &Settings) -> anyhow::Result<()> {
|
|||||||
("ping", &_rep),
|
("ping", &_rep),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3);
|
||||||
|
let client = ClientBuilder::new(reqwest::Client::new())
|
||||||
|
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
|
||||||
|
.build();
|
||||||
|
|
||||||
let url = reqwest::Url::parse_with_params(&settings.server_url, ¶ms)?;
|
let url = reqwest::Url::parse_with_params(&settings.server_url, ¶ms)?;
|
||||||
let urls: String = url.clone().into();
|
let urls: String = url.clone().into();
|
||||||
let resp = reqwest::get(url).await?.text().await?;
|
let resp = client.get(url).send().await?.text().await?;
|
||||||
tracing::info!(url=urls, resp=resp, "上报了硬盘可用空间");
|
tracing::info!(url=urls, resp=resp, "上报了硬盘可用空间");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user