ServerStatus-Rust Documentation

repository·master·Indexed 25 days ago

https://github.com/zdz/serverstatus-rust

A lightweight, high-performance VPS monitoring tool written in Rust. It provides a simpler alternative to Prometheus/Grafana for monitoring multiple small servers, featuring single-binary deployment for both server and client. Supports multi-platform operation (Linux, MacOS, Windows, Android, Raspberry Pi), alerting via Telegram, WeChat, email, and webhooks, and traffic statistics integration with vnstat. Includes both a high-performance Rust client (stat_client) and a cross-platform Python client.

Tokens
14.1K
Snippets
29
Records
76
Agent score
80%

What's inside ServerStatus-Rust

  1. Overview of ServerStatus-Rust features

    master

    ServerStatus-Rust is a lightweight, high-performance monitoring probe rewritten in Rust. Key features include:

    • Single Binary Deployment: Both server and client are single executables.
    • Multi-Platform Support: Linux, MacOS, Windows, Android, and Raspberry Pi.
    • Alerting: Supports status changes and custom rule alerts via telegram, wechat, email, and webhook.
    • Flexible Reporting: Supports http protocol reporting, making it compatible with free container services and Cloudflare optimization.
    • Advanced Deployment: Supports cloudflare tunnels, mTLS, and systemd auto-start.
    • Dynamic Registration: Supports host grouping for simplified configuration.
    • Traffic Statistics: Integrates with vnstat for monthly traffic statistics that persist across reboots.
  2. Deploy ServerStatus-Rust to Heroku

    master

    Deploying involves preparing the binary, configuration, and a Procfile, creating a Heroku app, setting a custom buildpack, and pushing the code via Git.

    1. Prepare Files

    You need the compiled Rust binary (stat_server), a config.toml file, and a Procfile.

    2. Create App and Set Buildpack

    Create the app using the CLI and set the custom empty buildpack required for this deployment.

    3. Deploy via Git

    Initialize a local Git repository, link it to Heroku, and push your code to the main branch.

    # 1. Prepare files (Example using v1.7.2)
    mkdir ServerStatus-Rust && cd ServerStatus-Rust
    wget https://github.com/zdz/ServerStatus-Rust/releases/download/v1.7.2/server-x86_64-unknown-linux-musl.zip
    unzip server-x86_64-unknown-linux-musl.zip
    rm -f stat_server.service server-x86_64-unknown-linux-musl.zip
    wget https://github.com/kissyouhunter/ServerStatus-Rust/raw/heroku/heroku/Procfile
    
    # 2. Create app and set buildpack
    heroku apps:create serverstatus-rust-heroku
    heroku buildpacks:set https://github.com/kissyouhunter/heroku-empty-build.git -a serverstatus-rust-heroku
    
    # 3. Deploy code
    git init
    heroku git:remote -a serverstatus-rust-heroku
    git checkout -b main
    git branch -D master
    git add .
    git commit -m "deploy app"
    git push heroku main
  3. Enable `vnstat` for traffic statistics

    master

    To ensure traffic data (monthly/total) is not lost during reboots, you can use vnstat on the client side. The server will then rely on the client's vnstat data.

    1. Install vnstat on the Client

    • Ubuntu/Debian: sudo apt install -y vnstat
    • CentOS: sudo yum install -y vnstat (requires epel-release)

    2. Configure vnstat

    Edit /etc/vnstat.conf if necessary:

    • Set BandwidthDetection 0 and MaxBandwidth 0.
    • If your interface is not eth0, set Interface "" to allow automatic detection.
    • Restart the service: systemctl restart vnstat.
    • Ensure version is $\ge 2.6$ using vnstat --version.

    3. Enable in Client

    Pass the -n flag when running the client:

    Rust Client:

    ./stat_client -a "grpc://127.0.0.1:9394" -u h1 -p p1 -n

    Python Client:

    python3 stat_client.py -a "http://127.0.0.1:8080/report" -u h1 -p p1 -n
  4. Build ServerStatus-Rust from source

    master

    You can build the project using cargo or by cloning the repository and building it manually.

    Option 1: Install via Cargo

    cargo install stat_server
    cargo install stat_client

    Option 2: Manual Build

    1. Install the Rust compiler using rustup.
    2. Install openssl-devel (for CentOS/RHEL systems).
    3. Clone the repository and run cargo build --release.

    Compiled binaries will be located in the target/release directory.

    # Install via cargo
    cargo install stat_server
    cargo install stat_client
    
    # OR Manual build
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    yum install -y openssl-devel
    git clone https://github.com/zdz/ServerStatus-Rust.git
    cd ServerStatus-Rust
    cargo build --release
  5. Quick Start Installation for CentOS/Debian/Ubuntu x86_64

    master

    To quickly experience ServerStatus-Rust on an x86_64 architecture running CentOS, Debian, or Ubuntu, follow these steps:

    1. Create and enter the installation directory:
      mkdir -p /opt/ServerStatus && cd /opt/ServerStatus
    2. Ensure unzip is installed (use apt install -y unzip or yum install -y unzip).
    3. Download and execute the one-touch deployment script:
      wget --no-check-certificate -qO one-touch.sh 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/scripts/one-touch.sh'
      bash -ex one-touch.sh
    4. Once deployed, access the dashboard at http://127.0.0.1:8080/ or http://<YOUR_IP>:8080/.

    For custom deployments, refer to the scripts/one-touch.sh script in the repository.

    mkdir -p /opt/ServerStatus && cd /opt/ServerStatus
    # apt install -y unzip / yum install -y unzip
    wget --no-check-certificate -qO one-touch.sh 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/scripts/one-touch.sh'
    bash -ex one-touch.sh
  6. Configure Custom Domains and SSL on Heroku

    master

    To use a custom domain and SSL (HTTPS), your Heroku Dyno must be set to the basic tier or higher.

    1. Change Dyno Type: Use heroku ps:type to check and set the tier to basic.
    2. Add Domain: Add your domain via the Heroku Dashboard (Settings -> Domains) and point your DNS CNAME to the provided Heroku DNS Target.
    3. Enable SSL: In the Heroku Dashboard, go to SSL Certificates and select Automatic Certificate Management (ACM).
  7. Run the Server manually or via Docker

    master

    Manual Execution

    You can run the stat_server binary directly. Use the -c flag to specify your configuration file.

    • Basic run: ./stat_server -c config.toml
    • With debug logging: RUST_BACKTRACE=1 RUST_LOG=trace ./stat_server -c config.toml
    • Test configuration validity: ./stat_server -c config.toml -t
    • Test notifications: ./stat_server -c config.toml --notify-test

    Docker Deployment

    To deploy using Docker Compose, download the necessary files and run docker-compose up -d:

    wget --no-check-certificate -qO docker-compose.yml 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/docker-compose.yml'
    wget --no-check-certificate -qO config.toml 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/config.toml'
    touch stats.json
    docker-compose up -d
    ./stat_server -c config.toml
  8. Use the Python Client (`stat_client.py`)

    master

    The Python client is a cross-platform alternative to the Rust client. It requires psutil, requests, and py-cpuinfo.

    Installation

    Ubuntu/Debian:

    apt -y install python3-pip
    python3 -m pip install psutil requests py-cpuinfo

    CentOS:

    yum -y install epel-release
    yum -y install python3-pip gcc python3-devel
    python3 -m pip install psutil requests py-cpuinfo

    Windows:

    pip install psutil requests py-cpuinfo

    Usage

    Download the script and run it with the same argument structure as the Rust client:

    python3 stat_client.py -a "http://127.0.0.1:8080/report" -u h1 -p p1
  9. Use a custom theme with Nginx

    master

    To use a custom theme, host your theme files in a specific directory (e.g., /opt/ServerStatus/web) and configure Nginx to serve those files. If a requested file does not exist in the theme directory, Nginx should fall back to proxying the request to the ServerStatus backend running at http://127.0.0.1:8080 using the @proxy location block.

    Ensure you include the necessary headers for proxying, including Upgrade and Connection for WebSocket support if required.

    server {
      # ssl, domain 等其它 nginx 配置
    
      # 自动反代所有请求
      location @proxy {
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host  $host;
        proxy_set_header X-Forwarded-Port  $server_port;
    		proxy_set_header Upgrade $http_upgrade;
    		proxy_set_header Connection $http_connection;
    
        proxy_pass http://127.0.0.1:8080;
      }
    
      # 如果主题存在相关文件则使用,否则回退到上游
      location / {
        root   /opt/ServerStatus/web; # 你自己修改的主题目录
        index  index.html index.htm;
        try_files $uri $uri/ @proxy;
      }
    }
  10. Install the Heroku CLI

    master
    To manage and run ServerStatus-Rust on Heroku, you must install the Heroku CLI. On Ubuntu/Debian systems, ensure you have unzip, git, curl, wget, nano, and vim installed. You can use the official installation script to install the CLI and an optional plugin for managing multiple accounts.