### Install Python Client Dependencies (Windows) Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Instructions for setting up the Python client on Windows, including installing Python 3.10, adding it to PATH, and installing necessary libraries via pip. ```bash # 安装 python 3.10 版本,并设置环境变量 # 命令行执行 pip install psutil requests # 下载 https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/client/stat_client.py pip install psutil requests py-cpuinfo ``` -------------------------------- ### Untitled No description -------------------------------- ### stat_client Installation and Configuration (Bash) Source: https://context7.com/zdz/serverstatus-rust/llms.txt These examples show how to install and configure the `stat_client` utility. It can be run with various command-line arguments for server address, user, password, reporting intervals, network interface selection, and other monitoring options. Environment variables can also be used for configuration. Some options allow viewing system or IP information without reporting. ```bash # Basic client configuration with HTTP ./stat_client -a "http://127.0.0.1:8080/report" -u h1 -p p1 # Client with all monitoring features enabled ./stat_client \ -a "http://your-server.com/report" \ -u server01 \ -p securepass123 \ -n \ --vnstat-mr 1 \ --interval 2 \ -w 10 # Client using environment variables (example.env) export SSR_ADDR=http://127.0.0.1:8080/report export SSR_USER=h1 export SSR_PASS=p1 export SSR_VNSTAT=true export SSR_DISABLE_PING=false ./stat_client # Group-based dynamic registration ./stat_client -a "http://127.0.0.1:8080/report" -g production -p grouppass --alias "Web Server 01" # Client with specific network interface monitoring ./stat_client -a "http://127.0.0.1:8080/report" -u h1 -p p1 -i eth0,eth1 # Client excluding certain network interfaces ./stat_client -a "http://127.0.0.1:8080/report" -u h1 -p p1 -e "lo,docker,vnet" # Disable TCP/UDP/process/thread counting (lower CPU usage) ./stat_client -a "http://127.0.0.1:8080/report" -u h1 -p p1 --disable-tupd # Disable network ping tests ./stat_client -a "http://127.0.0.1:8080/report" -u h1 -p p1 --disable-ping # View system information without reporting ./stat_client --sys-info # View IP information ./stat_client --ip-info ``` -------------------------------- ### Run Python Client Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Example commands to run the Python client, specifying the server address, username, and password. ```bash python3 stat_client.py -h python3 stat_client.py -a "http://127.0.0.1:8080/report" -u h1 -p p1 ``` -------------------------------- ### Untitled No description -------------------------------- ### Automated ServerStatus-Rust Installation with one-touch.sh Source: https://context7.com/zdz/serverstatus-rust/llms.txt This script automates the installation of ServerStatus-Rust server and client components on CentOS, Debian, and Ubuntu systems. It downloads the necessary binaries, sets up systemd services, and configures monitoring with minimal user interaction. Access the dashboard via HTTP on port 8080. ```bash # Quick server deployment on CentOS/Debian/Ubuntu mkdir -p /opt/ServerStatus && cd /opt/ServerStatus 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 # Access dashboard at http://your-server-ip:8080 # Using management script for installation wget --no-check-certificate -qO status.sh 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/scripts/status.sh' # Install server bash status.sh -i -s # Install client with manual configuration bash status.sh -i -c # Install client with automatic configuration bash status.sh -i -c http://username:password@server-ip:8080 # Examples: bash status.sh -i -c grpc://h1:p1@127.0.0.1:9394 bash status.sh -i -c http://h1:p1@example.com:8080 # Upgrade server and client bash status.sh -up -a # Manage services bash status.sh -s start # Start server bash status.sh -s stop # Stop server bash status.sh -s restart # Restart server bash status.sh -c status # Check client status ``` -------------------------------- ### Install Rust and Compile ServerStatus-Rust Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md This snippet provides the necessary commands to install the Rust compiler using rustup, install OpenSSL development headers, clone the ServerStatus-Rust repository, and compile the project in release mode. The compiled binary will be located in `target/release`. ```bash 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 ``` -------------------------------- ### Install Python Client Dependencies (Ubuntu/Debian) Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Installs python3-pip on Ubuntu/Debian systems and then installs Python client libraries using pip. ```bash apt -y install python3-pip python3 -m pip install psutil requests py-cpuinfo ``` -------------------------------- ### Install Python Client Dependencies (Alpine Linux) Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Installs required packages for Alpine Linux including wget, python3, pip, gcc, and development headers, followed by installing Python client libraries. ```bash apk add wget python3 py3-pip gcc python3-dev musl-dev linux-headers apk add procps iproute2 coreutils python3 -m pip install psutil requests py-cpuinfo ``` -------------------------------- ### Untitled No description -------------------------------- ### Generate and Install ServerStatus-Rust Client via /i Endpoint Source: https://context7.com/zdz/serverstatus-rust/llms.txt This utilizes the `/i` endpoint on the ServerStatus server to generate a customized client installation script. The script is downloaded using `curl` and then executed with `bash`. This allows for automatic configuration of client settings, including authentication, group IDs, aliases, and monitoring options. ```bash # Generate client installation script for static host curl -o install.sh "http://your-server.com/i?uid=h1&pass=p1" bash install.sh # Generate script for group-based host with custom options curl -o install.sh "http://your-server.com/i?gid=production&pass=grouppass&alias=web-01&vnstat=1&weight=10&loc=🏠&type=kvm" bash install.sh # Generate script with monitoring options disabled curl -o install.sh "http://your-server.com/i?uid=h2&pass=p2&ping=0&tupd=0&extra=0" bash install.sh # Generate script with specific network interfaces curl -o install.sh "http://your-server.com/i?uid=h3&pass=p3&iface=eth0,eth1" bash install.sh # Generate script with custom ping endpoints curl -o install.sh "http://your-server.com/i?uid=h4&pass=p4&cm=mobile.example.com:80&ct=telecom.example.com:80&cu=unicom.example.com:80" bash install.sh # The generated script includes: # - Binary download and installation # - Systemd service creation # - Automatic startup configuration # - All parameters properly escaped and configured ``` -------------------------------- ### Install vnStat (Ubuntu/Debian) Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Installs the vnStat traffic monitoring tool on Ubuntu/Debian systems using apt. ```bash sudo apt install -y vnstat ``` -------------------------------- ### Untitled No description -------------------------------- ### Install Python Client Dependencies (CentOS) Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Installs necessary packages like epel-release, python3-pip, gcc, and python3-devel on CentOS systems before installing Python client libraries. ```bash yum -y install epel-release yum -y install python3-pip gcc python3-devel python3 -m pip install psutil requests py-cpuinfo ``` -------------------------------- ### Install Heroku Accounts Plugin Source: https://github.com/zdz/serverstatus-rust/blob/master/heroku/README.md Installs the `heroku-accounts` plugin, which allows for managing multiple Heroku accounts from the command line. ```bash heroku plugins:install heroku-accounts ``` -------------------------------- ### Untitled No description -------------------------------- ### Install vnStat (CentOS) Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Installs the vnStat traffic monitoring tool on CentOS systems using yum. ```bash sudo yum install epel-release -y sudo yum install -y vnstat ``` -------------------------------- ### Enable vnStat Support in Client Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Examples of running the client with the '-n' flag to enable vnStat statistics, shown for both the Rust binary and the Python script. ```bash # client 使用 -n 参数开启 vnstat 统计 ./stat_client -a "grpc://127.0.0.1:9394" -u h1 -p p1 -n # 或 python3 stat_client.py -a "http://127.0.0.1:8080/report" -u h1 -p p1 -n ``` -------------------------------- ### Install Heroku CLI on Ubuntu/Debian Source: https://github.com/zdz/serverstatus-rust/blob/master/heroku/README.md Installs the Heroku Command Line Interface (CLI) on Ubuntu/Debian systems using a curl script. This tool is essential for managing Heroku applications. ```bash curl https://cli-assets.heroku.com/install.sh | sh ``` -------------------------------- ### Untitled No description -------------------------------- ### Configure and Run Server with gRPC (Bash) Source: https://context7.com/zdz/serverstatus-rust/llms.txt Configures the ServerStatus-Rust server to use gRPC for reporting, including optional TLS/mTLS encryption, by modifying the `config.toml` file. It then demonstrates starting the server with this configuration. The `grpc_addr` and `grpc_tls` settings are crucial for enabling the gRPC service. ```bash cat > config.toml << 'EOF' grpc_addr = "0.0.0.0:9394" http_addr = "0.0.0.0:8080" grpc_tls = 1 # 0: disabled, 1: TLS, 2: mTLS tls_dir = "tls" offline_threshold = 30 hosts = [ {name = "h1", password = "p1", alias = "Server 1", location = "🏠"}, ] EOF ``` ```bash ./stat_server -c config.toml ``` -------------------------------- ### Check vnStat Version and Test Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Checks the installed vnStat version and tests monthly traffic data retrieval using both command-line and JSON output. ```bash # 确保 version >= 2.6 vnstat --version # 测试查看月流量 (刚安装可能需等一小段时间来采集数据) vnstat -m vnstat --json m ``` -------------------------------- ### Connect Client via gRPC to Server (Bash) Source: https://context7.com/zdz/serverstatus-rust/llms.txt Shows how to connect the ServerStatus-Rust client to the server's gRPC reporting service. Examples include connecting with standard credentials and with mTLS enabled, specifying the server address (`-a`), username (`-u`), password (`-p`), and optionally mTLS settings. ```bash ./stat_client -a "grpc://127.0.0.1:9394" -u h1 -p p1 ``` ```bash ./stat_client -a "grpc://127.0.0.1:9394" -u h1 -p p1 --mtls --tls-dir tls ``` -------------------------------- ### Access Server Configuration with JWT (curl) Source: https://context7.com/zdz/serverstatus-rust/llms.txt This snippet demonstrates how to access the server's configuration details via the API using a JWT. It involves a GET request to the `/api/admin/config.json` endpoint, including the `Authorization` header with the Bearer token. ```shell # Access server configuration curl http://127.0.0.1:8080/api/admin/config.json \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ``` -------------------------------- ### Prepare ServerStatus-Rust Files Source: https://github.com/zdz/serverstatus-rust/blob/master/heroku/README.md Prepares the necessary files for deployment by creating a directory, downloading the compiled Rust binary, the configuration file, and the Procfile. ```bash mkdir ServerStatus-Rust && cd ServerStatus-Rust # 下载示例以 v1.7.2 为例 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 ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### GET /json/stats.json Source: https://context7.com/zdz/serverstatus-rust/llms.txt Returns current monitoring statistics for all registered hosts in JSON format. This endpoint is publicly accessible and used by the web dashboard. ```APIDOC ## GET /json/stats.json ### Description Returns current monitoring statistics for all registered hosts in JSON format. This endpoint is publicly accessible and provides data for the web dashboard. ### Method GET ### Endpoint /json/stats.json ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash # Fetch current stats curl http://127.0.0.1:8080/json/stats.json ``` ### Response #### Success Response (200) - **updated** (integer) - Timestamp of the last update. - **servers** (array) - An array of server objects, each containing detailed statistics. - **name** (string) - Server hostname. - **alias** (string) - Server alias. - **type** (string) - Server virtualization type (e.g., "kvm"). - **location** (string) - Server location identifier. - **online4** (boolean) - Indicates if IPv4 is online. - **online6** (boolean) - Indicates if IPv6 is online. - **uptime** (string) - Server uptime duration. - **load_1** (number) - System load average for the last 1 minute. - **load_5** (number) - System load average for the last 5 minutes. - **load_15** (number) - System load average for the last 15 minutes. - **cpu** (number) - CPU utilization percentage. - **memory_total** (integer) - Total system memory in bytes. - **memory_used** (integer) - Used system memory in bytes. - **swap_total** (integer) - Total swap space in bytes. - **swap_used** (integer) - Used swap space in bytes. - **hdd_total** (integer) - Total disk space in bytes. - **hdd_used** (integer) - Used disk space in bytes. - **network_rx** (integer) - Total bytes received. - **network_tx** (integer) - Total bytes transmitted. - **network_in** (integer) - Current network receive rate. - **network_out** (integer) - Current network transmit rate. - **ping_10010** (number) - Ping latency to a specific IP (example). - **ping_189** (number) - Ping latency to a specific IP (example). - **ping_10086** (number) - Ping latency to a specific IP (example). #### Response Example ```json { "updated": 1698765432, "servers": [ { "name": "h1", "alias": "Production Server", "type": "kvm", "location": "🏠", "online4": true, "online6": false, "uptime": "15 days 3 hours", "load_1": 0.45, "load_5": 0.52, "load_15": 0.48, "cpu": 18.5, "memory_total": 8589934592, "memory_used": 3221225472, "swap_total": 2147483648, "swap_used": 0, "hdd_total": 107374182400, "hdd_used": 42949672960, "network_rx": 5368709120, "network_tx": 2684354560, "network_in": 2048000, "network_out": 1024000, "ping_10010": 25.3, "ping_189": 28.1, "ping_10086": 23.7 } ] } ``` ``` -------------------------------- ### Initialize Git and Deploy to Heroku Source: https://github.com/zdz/serverstatus-rust/blob/master/heroku/README.md Initializes a Git repository, configures user email, sets the Heroku app as a remote, and pushes the code to Heroku for deployment. This process deploys the prepared files to the Heroku application. ```bash git init git config user.email "admin@heroku.com" 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 ``` -------------------------------- ### Compile ServerStatus-Rust from Source Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Commands to compile the ServerStatus server and client binaries directly from their source code using Cargo, the Rust build tool and package manager. ```bash # cargo install stat_server cargo install stat_client # or ``` -------------------------------- ### Untitled No description -------------------------------- ### Access Server Stats with JWT (curl) Source: https://context7.com/zdz/serverstatus-rust/llms.txt This snippet shows how to access detailed server statistics via the API using an obtained JWT. It requires a GET request to the `/api/admin/stats.json` endpoint with the `Authorization` header set to `Bearer `. ```shell # Access detailed stats with JWT curl http://127.0.0.1:8080/api/admin/stats.json \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Add and Set Heroku Account Source: https://github.com/zdz/serverstatus-rust/blob/master/heroku/README.md Demonstrates how to add a Heroku account using its email and API key, and how to set it as the active account for subsequent commands. ```bash heroku accounts:add admin@heroku.com Enter your Heroku credentials. Email: admin@heroku.com Password: ******** heroku accounts:set 账户别名 ``` -------------------------------- ### Download Python Client Script Source: https://github.com/zdz/serverstatus-rust/blob/master/README.md Downloads the Python client script 'stat_client.py' from a GitHub raw URL using wget. ```bash wget --no-check-certificate -qO stat_client.py 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/client/stat_client.py' ``` -------------------------------- ### Untitled No description -------------------------------- ### Create Heroku App and Set Buildpack Source: https://github.com/zdz/serverstatus-rust/blob/master/heroku/README.md Creates a new Heroku application and sets a custom buildpack for it. The `heroku-empty-build.git` buildpack is used, implying that the application is pre-compiled. ```bash heroku apps:create serverstatus-rust-heroku heroku buildpacks:set https://github.com/kissyouhunter/heroku-empty-build.git -a serverstatus-rust-heroku ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Initialize Leaflet Map and Tile Layer (JavaScript) Source: https://github.com/zdz/serverstatus-rust/blob/master/web/jinja/map.jinja.html Initializes a Leaflet map centered at [0, 0] with zoom level 2. It then sets up a tile layer using MapTiler's streets map, requiring an API key. The layer includes attribution for MapTiler and OpenStreetMap contributors and is configured for optimal performance with tileSize and zoomOffset. ```javascript var map = L.map('map').setView([0, 0], 2); L.tileLayer('https://api.maptiler.com/maps/streets/{z}/{x}/{y}@2x.png?key=jHmRwldTtA3Fbbl7f20d', { tileSize: 512, zoomOffset: -1, minZoom: 1, attribution: "\u003ca href=\"https://www.maptiler.com/copyright/\" target=\"\_blank\"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca href=\"https://www.openstreetmap.org/copyright\" target=\"\_blank\"\u003e\u0026copy; OpenStreetMap contributors\u003c/a\u003e", crossOrigin: true }).addTo(map); ``` -------------------------------- ### Server Configuration File (TOML) Source: https://context7.com/zdz/serverstatus-rust/llms.txt This TOML file defines the configuration for the ServerStatus server. It includes settings for listening addresses (gRPC and HTTP), TLS/mTLS, JWT secret, admin credentials, static host definitions, dynamic host group registration, and notification templates for Telegram and email. ```toml # Server listening configuration grpc_addr = "0.0.0.0:9394" http_addr = "0.0.0.0:8080" offline_threshold = 30 # TLS/mTLS configuration grpc_tls = 0 # 0: disabled, 1: TLS, 2: mTLS tls_dir = "tls" # Admin credentials for /detail and /map pages jwt_secret = "generate_with_openssl_rand_base64_16" admin_user = "admin" admin_pass = "secure_password" # Static host configuration hosts = [ {name = "h1", password = "p1", alias = "Production Server", location = "🏠", type = "kvm", labels = "os=ubuntu;ndd=2024/12/31;spec=4C/8G/100G;"}, {name = "h2", password = "p2", alias = "Backup Server", location = "🏢", type = "kvm", monthstart = 1}, {name = "h3", password = "p3", alias = "Test Server", location = "cn", type = "kvm", notify = true}, ] # Dynamic host group registration hosts_group = [ {gid = "production", password = "prod_pass", location = "🏠", type = "kvm", notify = true}, {gid = "development", password = "dev_pass", location = "🏢", type = "kvm", notify = false}, {gid = "silent", password = "silent_pass", location = "🏡", type = "kvm", notify = false}, ] group_gc = 30 workspace = "/opt/ServerStatus" notify_interval = 30 # Telegram notification [tgbot] enabled = true bot_token = "1234567890:ABCdefGHIjklMNOpqrsTUVwxyz" chat_id = "-1001234567890" title = "❗Server Status" online_tpl = "{{config.title}} \n😆 {{host.location}} {{host.name}} is back online" offline_tpl = "{{config.title}} \n😱 {{host.location}} {{host.name}} is offline" custom_tpl = """ {% if host.memory_used / host.memory_total > 0.8 %}
😲 {{host.name}} memory usage exceeds 80%, current {{ (100 * host.memory_used / host.memory_total) | round }}%
{% endif %} {% if host.hdd_used / host.hdd_total > 0.8 %}
😲 {{host.name}} disk usage exceeds 80%, current {{ (100 * host.hdd_used / host.hdd_total) | round }}%
{% endif %} """ # Email notification [email] enabled = false server = "smtp.gmail.com" username = "alerts@example.com" password = "app_password" to = "admin@example.com;ops@example.com" subject = "ServerStatus Alert" ``` -------------------------------- ### HTTP POST to Report Server Status (Bash) Source: https://context7.com/zdz/serverstatus-rust/llms.txt Demonstrates how to report server monitoring data to the ServerStatus-Rust server via HTTP POST requests. Supports both Protocol Buffers (binary) and JSON formats. Authentication is handled via HTTP Basic Auth. The `ssr-auth` header specifies whether it's a single host or group registration. ```bash curl -X POST http://127.0.0.1:8080/report \ -u "h1:p1" \ -H "Content-Type: application/octet-stream" \ -H "ssr-auth: single" \ --data-binary @stat_request.bin ``` ```bash curl -X POST http://127.0.0.1:8080/report \ -u "h1:p1" \ -H "Content-Type: application/json" \ -H "ssr-auth: single" \ -d '{ "name": "h1", "frame": "data", "online4": true, "online6": false, "uptime": 3600, "load_1": 0.5, "load_5": 0.6, "load_15": 0.7, "cpu": 25.5, "memory_total": 8589934592, "memory_used": 4294967296, "swap_total": 2147483648, "swap_used": 0, "hdd_total": 107374182400, "hdd_used": 53687091200, "network_rx": 1073741824, "network_tx": 536870912, "network_in": 1024000, "network_out": 512000 }' ``` ```bash curl -X POST http://127.0.0.1:8080/report \ -u "g1:pp" \ -H "Content-Type: application/json" \ -H "ssr-auth: group" \ -d '{"name": "server-001", "gid": "g1", "alias": "Production Server 1", "cpu": 15.2}' ```