Skip to content

Commit

Permalink
Added release macos,windows,pi,android
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz committed Feb 10, 2023
1 parent 61b0ee0 commit 71b363d
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 97 deletions.
138 changes: 102 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- "*"
- "v*"

workflow_dispatch:

Expand All @@ -14,64 +14,118 @@ jobs:
release:
name: Cross build for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
suffix: ""
use-cross: true
cargo-flags: "--no-default-features --features stat_client/native"
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
suffix: ""
use-cross: true
cargo-flags: "--no-default-features --features stat_client/native"

# - os: macos-latest
# target: x86_64-apple-darwin
# suffix: ""
# - os: macos-latest
# target: aarch64-apple-darwin
# suffix: ""
- os: ubuntu-latest
target: aarch64-linux-android
suffix: ""
use-cross: true
cargo-flags: ""
# 32bit
- os: ubuntu-latest
target: armv7-linux-androideabi
suffix: ""
use-cross: true
cargo-flags: ""

- os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
suffix: ""
use-cross: true
cargo-flags: ""

- os: macos-latest
target: x86_64-apple-darwin
suffix: ""
use-cross: false
cargo-flags: ""
- os: macos-latest
target: aarch64-apple-darwin
suffix: ""
use-cross: true
cargo-flags: ""

- os: windows-latest
target: x86_64-pc-windows-msvc
suffix: .exe
use-cross: false
cargo-flags: ""
# - os: windows-latest
# target: x86_64-pc-windows-msvc
# target: x86_64-pc-windows-gnu
# suffix: .exe
# use-cross: false
# cargo-flags: ""

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
toolchain: stable
- name: Install cross
run: cargo install cross
- name: Run tests
run: cross test --release --target ${{ matrix.target }} --verbose
target: ${{ matrix.target }}

- name: Install Protoc
if: matrix.os == 'windows-latest'
uses: arduino/setup-protoc@v1
with:
version: '3.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build release
run: cross build --release --target ${{ matrix.target }}
uses: actions-rs/cargo@v1
with:
command: build
use-cross: ${{ matrix.use-cross }}
args: --locked --release --target=${{ matrix.target }} ${{ matrix.cargo-flags }}

- name: Install LLVM Strip
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y llvm
- name: Strip (MacOS/Window)
if: matrix.os != 'ubuntu-latest'
continue-on-error: true
run: |
strip target/${{ matrix.target }}/release/stat_server${{matrix.suffix}}
strip target/${{ matrix.target }}/release/stat_client${{matrix.suffix}}
cp config.toml target/${{ matrix.target }}/release/
cp systemd/stat_server.service target/${{ matrix.target }}/release/
cp systemd/stat_client.service target/${{ matrix.target }}/release/
- name: LLVM Strip
- name: LLVM Strip (Linux)
if: matrix.os == 'ubuntu-latest'
continue-on-error: true
run: |
sudo apt-get install -y llvm
llvm-strip target/${{ matrix.target }}/release/stat_server${{matrix.suffix}}
llvm-strip target/${{ matrix.target }}/release/stat_client${{matrix.suffix}}
cp config.toml target/${{ matrix.target }}/release/
cp systemd/stat_server.service target/${{ matrix.target }}/release/
cp systemd/stat_client.service target/${{ matrix.target }}/release/
- name: Run UPX
- name: Compress binaries
# Upx may not support some platforms. Ignore the errors
continue-on-error: true
# Disable upx for mips. See https://github.com/upx/upx/issues/387
if: matrix.os == 'ubuntu-latest' && !contains(matrix.target, 'mips')
uses: crazy-max/ghaction-upx@v2
if: true && !contains(matrix.target, 'mips')
uses: svenstaro/upx-action@v2
with:
version: latest
strip: false
args: -q --best --lzma
files: |
target/${{ matrix.target }}/release/stat_server${{matrix.suffix}}
target/${{ matrix.target }}/release/stat_client${{matrix.suffix}}
args: -q --best --lzma
- uses: actions/upload-artifact@v3
with:
Expand All @@ -83,8 +137,8 @@ jobs:
target/${{ matrix.target }}/release/stat_server.service
target/${{ matrix.target }}/release/stat_client.service
- name: Zip Release For Server
if: matrix.os == 'ubuntu-latest'
- name: Zip Release For Server (Linux)
if: matrix.os == 'ubuntu-latest' && contains(matrix.target, 'linux')
uses: TheDoctor0/[email protected]
with:
type: zip
Expand All @@ -95,8 +149,8 @@ jobs:
stat_server.service
config.toml
- name: Zip Release For Client
if: matrix.os == 'ubuntu-latest'
- name: Zip Release For Client (Linux)
if: matrix.os == 'ubuntu-latest' && contains(matrix.target, 'linux')
uses: TheDoctor0/[email protected]
with:
type: zip
Expand All @@ -106,20 +160,32 @@ jobs:
stat_client${{matrix.suffix}}
stat_client.service
# - name: Zip Release For MacOS/Win
# if: matrix.os != 'ubuntu-latest'
# uses: TheDoctor0/[email protected]
# with:
# type: zip
# filename: ServerStatus-${{ matrix.target }}.zip
# directory: target/${{ matrix.target }}/release/
# path: |
# stat_server${{matrix.suffix}}
# stat_client${{matrix.suffix}}
- name: Zip Release For Server (MacOS/Window)
if: true && !contains(matrix.target, 'linux')
uses: TheDoctor0/[email protected]
with:
type: zip
filename: server-${{ matrix.target }}.zip
directory: target/${{ matrix.target }}/release/
path: |
stat_server${{matrix.suffix}}
config.toml
- name: Zip Release For Client (MacOS/Window)
if: true && !contains(matrix.target, 'linux')
uses: TheDoctor0/[email protected]
with:
type: zip
filename: client-${{ matrix.target }}.zip
directory: target/${{ matrix.target }}/release/
path: |
stat_client${{matrix.suffix}}
- name: Publish
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
target/${{ matrix.target }}/release/server-${{ matrix.target }}.zip
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
`ServerStatus` 威力加强版,保持轻量和简单部署,增加以下主要特性:

- 使用 `rust` 完全重写 `server``client`,单个执行文件部署
- 支持上下线和简单自定义规则告警 (`telegram``wechat``email``webhook`)
- 多系统支持 `Linux``MacOS``Windows``Android``Raspberry Pi`
- 支持上下线和简单自定义规则告警 (`telegram``wechat``email``webhook`)
- 支持 `http` 协议上报,方便部署到各免费容器服务和配合 `cf` 等优化上报链路
- 支持 `vnstat` 统计月流量,重启不丢流量数据
- 支持 `railway` 快速部署
Expand All @@ -77,6 +78,17 @@

📕 完整文档迁移至 [doc.ssr.rs](https://doc.ssr.rs)

| OS | Release |
| ---- | ---- |
| Linux x86_64 | x86_64-unknown-linux-musl |
| Linux arm64 | aarch64-unknown-linux-musl |
| MacOS x86_64 | x86_64-apple-darwin |
| MacOS arm64 | aarch64-apple-darwin |
| Windows x86_64 | x86_64-pc-windows-msvc |
| Raspberry Pi | armv7-unknown-linux-musleabihf |
| Android 64bit | aarch64-linux-android |
| Android 32bit | armv7-linux-androideabi |

### 🍀 主题

如果你觉得你创造/修改的主题还不错,欢迎分享/PR,前端单独部署方法参考 [#37](https://github.com/zdz/ServerStatus-Rust/discussions/37)
Expand All @@ -95,15 +107,15 @@ Hotaru 主题由 [@HinataKato](https://github.com/HinataKato) 修改提供,[

ServerStatus-web 主题由 [@mjjrock](https://github.com/mjjrock) 修改提供,[主题地址](https://github.com/mjjrock/ServerStatus-web)

演示:[Demo](https://ssr-web.vercel.app)

<img width="1425" alt="image" src="https://user-images.githubusercontent.com/102237118/171837653-3a5b2cd6-bf02-4602-a132-2c80a6707f68.png">

</details>


<details>
<summary>v1.5.7版本主题</summary>
<summary>v1.5.7 版本主题</summary>

[演示:Demo](https://tz-rust.vercel.app)

<img width="1215" alt="image" src="https://user-images.githubusercontent.com/152173/165957689-d35714a9-f7f8-49f7-9573-97d4cf3c2f79.png">
</details>
Expand All @@ -123,7 +135,7 @@ bash -ex one-touch.sh

### 2.2 快速部署

参见 [快速部署](https://doc.ssr.rs/rapid_deploy)
👉 [快速部署](https://doc.ssr.rs/rapid_deploy)

### 2.3 服务管理脚本部署,感谢 [@Colsro](https://github.com/Colsro) 提供
<details>
Expand Down Expand Up @@ -309,6 +321,7 @@ OPTIONS:
-g, --gid <GID> group id [default: ]
-h, --help Print help information
--ip-info show ip info, default:false
--sys-info show sys info, default:false
--json use json protocol, default:false
--location <LOCATION> location [default: ]
-n, --vnstat enable vnstat, default:false
Expand All @@ -321,6 +334,7 @@ OPTIONS:

# 一些参数说明
--ip-info # 显示本机ip信息后立即退出,目前使用 ip-api.com 数据
--sys-info # 显示本机系统信息后立即退出
--disable-extra # 不上报系统信息和IP信息
--disable-ping # 停用三网延时和丢包率探测
--disable-tupd # 不上报 tcp/udp/进程数/线程数,减少CPU占用
Expand Down Expand Up @@ -406,7 +420,7 @@ python3 stat_client.py -a "http://127.0.0.1:8080/report" -u h1 -p p1 -n
<details>
<summary>如何使用自定义主题</summary>

更灵活的方式见 [#37](https://github.com/zdz/ServerStatus-Rust/discussions/37)
更简单的方式 👉 [#37](https://github.com/zdz/ServerStatus-Rust/discussions/37)

```nginx
server {
Expand Down Expand Up @@ -478,7 +492,7 @@ OPTIONS:
<details>
<summary>关于这个轮子</summary>

之前一直在使用 `Prometheus` + `Grafana` + `Alertmanager` + `node_exporter` 做VPS监控,这也是业界比较成熟的监控方案,用过一段时间后,发现非生产环境,很多监控指标都用不上,反而显得有些重
之前一直在使用 `Prometheus` + `Grafana` + `Alertmanager` + `node_exporter` 做VPS监控,这也是业界比较成熟的监控方案,用过一段时间后,发现非生产环境,很多监控指标都用不上,运维成本有点大
`ServerStatus` 很好,足够简单和轻量,一眼可以看尽所有小机机,只是 `c++` 版本很久没迭代过,自己的一些需求在原版上不是很好修改,如自带 `tcp` 上报对跨区机器不是很友好,也不方便对上报的链路做优化 等等。这是学习 `Rust` 练手的小项目,所以不会增加复杂功能,保持小而美,简单部署,配合 [Uptime Kuma](https://github.com/louislam/uptime-kuma) 基本上可以满足个人大部分监控需求。

</details>
Expand Down
4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ reqwest = {version = "0.11", features = ["json", "rustls-tls", "brotli", "gzip",
serde = {version = "1.0", default-features = false, features = ["derive", "alloc"]}
serde_json = {version = "1.0", default-features = false, features = ["alloc"]}
stat_common = {path = "../common"}
sysinfo = "0.26"
sysinfo = "0.27.7"
tokio = {version = "1", features = ["full"]}
tonic = {version = "0.8", features = ["tokio-rustls"]}
tower = { version = "0.4" }
md5 = "0.7.0"

[features]
default = ["native"]
default = ["sysinfo"]
native = []
sysinfo = []
17 changes: 12 additions & 5 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub struct Args {
cm_addr: String,
#[arg(long = "cu", env = "SSR_CU_ADDR", default_value = CU, help = "China Unicom probe addr")]
cu_addr: String,
#[arg(long = "sys-info", help = "show sys info, default:false")]
sys_info: bool,
#[arg(long = "ip-info", help = "show ip info, default:false")]
ip_info: bool,
#[arg(long = "json", help = "use json protocol, default:false")]
Expand Down Expand Up @@ -155,7 +157,7 @@ fn sample_all(args: &Args, stat_base: &StatRequest) -> StatRequest {
// dbg!(&stat_base);
let mut stat_rt = stat_base.clone();

#[cfg(all(feature = "native", not(feature = "sysinfo")))]
#[cfg(all(feature = "native", not(feature = "sysinfo"), target_os = "linux"))]
status::sample(args, &mut stat_rt);
#[cfg(all(feature = "sysinfo", not(feature = "native")))]
sys_info::sample(args, &mut stat_rt);
Expand Down Expand Up @@ -303,24 +305,29 @@ async fn main() -> Result<()> {
eprintln!("sys id: {sys_id}");
eprintln!("sys info: {sys_info_json}");

if args.sys_info {
sys_info::print_sysinfo();
process::exit(0);
}

if let Ok(mut o) = G_CONFIG.lock() {
o.sys_info = Some(sys_info);
}

// use native
#[cfg(all(feature = "native", not(feature = "sysinfo")))]
#[cfg(all(feature = "native", not(feature = "sysinfo"), target_os = "linux"))]
{
eprintln!("enable feature native");
eprintln!("feature native enabled");
status::start_cpu_percent_collect_t();
status::start_net_speed_collect_t(&args);
}

// use sysinfo
#[cfg(all(feature = "sysinfo", not(feature = "native")))]
{
eprintln!("enable feature sysinfo");
eprintln!("feature sysinfo enabled");
sys_info::start_cpu_percent_collect_t();
sys_info::start_net_speed_collect_t();
sys_info::start_net_speed_collect_t(&args);
}

status::start_all_ping_collect_t(&args);
Expand Down
2 changes: 1 addition & 1 deletion client/src/status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #![allow(unused)]
#![allow(unused)]
use lazy_static::lazy_static;
use once_cell::sync::OnceCell;
use regex::Regex;
Expand Down
Loading

0 comments on commit 71b363d

Please sign in to comment.