Skip to content
lollipopkit edited this page Jul 19, 2023 · 16 revisions

English | 简体中文

In order to make full use of the functions of this project, you need to take the following steps:

Welcome

There are many ways:

Config

Server end

Docker compose

Install and run
version: "3.0"
services:
  srvbox:
    image: lollipopkit/srvbox_monitor:latest
    container_name: srvbox
    volumes:
      - ./config:/root/.config/server_box
    environment:
      - TZ=Asia/Shanghai
      # Custom listen address
      # - SBM_ADDR=0.0.0.0:3770
      # TLS Cert
      # - SBM_TLS_CRT=/root/.config/server_box/cert.pem
      # TLS Key
      # - SBM_TLS_KEY=/root/.config/server_box/key.pem
    ports:
      - 3770:3770

Choose a directory you like, write the above content into docker-compose.yml and run docker-compose up -d.

Update
  • docker rm srvbox -f && docker rmi lollipopkit/srvbox_monitor:latest to delete old image.
  • docker-compose up -d to run with new image.

Executable

Install
  • If you have go installed, you can run go install github.com/lollipopkit/server_box_monitor@latest
  • If you don't have go installed, you can download the binary from release page
Running continuously:

If you are using the executable file, you probably want it to run continuously. It is recommended to use systemd:

  • Example (Read comment!):
    [Unit]
    Description=ServerBox Monitor Service
    After=network.target
    
    [Service]
    Type=simple
    # Uncomment the following line to run as a specific user
    # User=root
    Restart=on-failure
    RestartSec=5s
    # Make sure the path is correct
    ExecStart=/usr/bin/server_box_monitor
    # Please change 'xxx' to your username
    WorkingDirectory=/home/xxx/.config/server_box
    
    [Install]
    WantedBy=default.target
    
  • Rootless
    • Copy file to ~/.config/systemd/user/srvbox.service
    • Run systemctl --user enable --now srvbox
    • You can run sudo loginctl enable-linger $USER to make the servicerun after logout
  • Rootful
    • Copy file to /etc/systemd/system/srvbox.service
    • Uncomment User in the file
    • Run systemctl enable --now srvbox
Update

You need manually update the executable file.

Confirm running

Before the next section, you need to confirm that the service is running, you can confirm it in the following ways:

  • If you are using Docker: docker logs srvbox
  • If you are using systemd: such as systemctl status srvbox
  • Web access http://DEVICE_IP:3770 (If you have modified the listening address, please replace it yourself)

If there is a display similar to the below, it means that the service has been successfully started and you can continue to the next step. Web display

Server config

Different installation methods, the configuration file is in different paths:

  • Executable: ~/.config/server_box/config.json
  • Docker: ./config/config.json

Here is a complete example of the server configuration, you need to modify it according to your needs:

{
    "version": 2,
    // Interval of checking
    // Valid formats: 1s 1m 1h
    // Default: 30s
    // Values less than 10s will be ignored
    "interval": "1m",
    // Rate limiter for msg push
    // eg: 3/1m (3 times every minute), 1/10s (1 time every 10 seconds)
    "rate": "1/10s",
    // Name of this host
	"name": "Server 1",
    // Check rules
    //
    // Type: 
    // cpu, mem, net, disk, temp (temperature), swap
    //
    // Threshold:
    // format: COMPARE_OPERATOR VALUE UNIT
    // COMPARE_OPERATOR: >, >=, <, <=, =
    // VALUE: int/float: 0.1 1 1.1
    // UNIT: % (percent), m/s (speed), m (size), c (celsius)
    // Speed only valid in per second: b/s k/s, m/s, g/s ...
    // 
    // Matcher:
    // cpu: cpu, cpu0, 1, 2, 3, ...
    // mem: free, used, avail
    // net: eth0, eth1-in, docker-out, ...
    // disk: /, /home, /dev/sda1, ...
    // temp: x86_pkg_temp, x86_core_temp, ...
    // swap: free, used
    "rules": [
        {
            "type": "cpu",
            "threshold": ">=77.7%",
            // "" / "cpu" -> all cpus, in this case, you can omit attribute "matcher"
            // "X" / "cpuX" -> NO.X cpu
            "matcher": "0"
        },
        {
            "type": "net",
            // speed only support per second
            "threshold": ">=7.7m/s",
            // network interface name
            "matcher": "eth0"
        },
        {
            "type": "temp",
            // temperature only support celsius
            "threshold": ">=37.7c",
            // you can run `cat /sys/class/thermal/thermal_zone*/type` to get all thermal types
            "matcher": "x86_pkg_temp"
        },
        {
            "type": "disk",
            "threshold": ">=77.7%",
            // mount point or filesystem
            // you can use `df -h` to get all valid matchers
            "matcher": "/dev/sda1"
        },
        {
            "type": "mem",
            // support: size, percent
            "threshold": "<=17.7%",
            // support: free, used, avail
            "matcher": "free"
        },
        {
            "type": "swap",
            // support: size, percent
            "threshold": ">=37.7%",
            // support: free, used
            "matcher": "used"
        }
    ],
    // Push rules
    //
    // type: webhook, ios, serverchan (more to come)
    // iface: interface for the push type
    // body_regex: regex to match the response body
    // code: response code to match
    //
    // Format args:
    // "{{msg}}" will be replaced with the message of the check result
    "pushes": [
        {
            // This is a example for QQ Group message
            "type": "webhook",
            "iface": {
                "name": "QQ Group",
                // Webhook url
                "url": "http://localhost:5700",
                // Headers for the request
                "headers": {
                    "Authorization": "Bearer YOUR_TOKEN",
                    "Content-Type": "application/json"
                },
                // UPPERCASED HTTP method
                "method": "POST",
                // Body for the request
                // {{key}} and {{value}} will be replaced with the key and value of the check result
                "body": {
                    "action": "send_group_msg",
                    "params": {
                        "group_id": 123456789,
                        "message": "Server name\n{{msg}}"
                    }
                },
                // Check push is successful or not:
                // Will skip if not set or empty
                // 
                // If the response body matches the regex, the push is considered successful
                "body_regex": ".*",
                // If the response code equals, the push is considered successful
                "code": 200
            }
        },
        {
            "type": "ios",
            "iface": {
                "name": "ServerBox iOS App",
                // You can get it from settings page of ServerBox iOS app
                "token": "YOUR_TOKEN",
                "title": "Server name",
                "content": "{{msg}}",
                "body_regex": ".*",
                "code": 200
            }
        },
        {
            "type": "server_chan",
            "iface": {
                "name": "ServerChan",
                // Details please refer to https://sct.ftqq.com/
                "sckey": "YOUR_SCKEY",
                "title": "Server Notification",
                "desp": "{{msg}}",
                "body_regex": ".*",
                "code": 200
            }
        }
    ]
}

App

iOS Push

In order to use App push, you need to get a Token in the App, you can find it in the settings page of the App.

Attention: Self-compiled version (non-AppStore version) cannot use the App push service provided by this project, you need to modify the source code of this project and compile it yourself, or build your own push service.

iOS Home Widget

  1. Add home widget
  2. Long press the widget and click Edit Widget
  3. Input Url,such as https://server1.srvbox.example.com/status
    • Url must end with /status, this is the api for getting status
    • Due to Apple's security policy, you must use https
    • If you don't know how to use reverse proxy and https, I recommend learning to use:
      • caddy will automatically configure https:
        # Make sure your domain name has been resolved to the target server, and replace the domain name below with your domain name
        # And replace DEVICE_IP with the IP of your server, if you install it on "localhost", please use 127.0.0.1
        server1.srvbox.example.com {
              reverse_proxy 127.0.0.1:3770
        }
        
      • Via tailscale access internal network service: https://server1:3770/status (server1 is the hostname provided by tailscale's Magic DNS)
    • You can use the internal network address
  4. Go back to the home screen

Attention:

  • You can repeat the above steps to add multiple widgets, each widget can use a different link, which can display the status of different servers.
  • Because of iOS restrictions, the fastest refresh rate is half an hour

Android home widget

  1. Add home widget
  2. Remember the ID display on the widget
  3. Open the app settings page, click Config home widget link
  4. Input with this format {"ID1": "URL1", "ID2": "URL2"}
    • eg: {"17": "https://example.com/status"}
  5. Save
  6. Back to home screen, and click the widget to refresh.

Attention:

  • You can repeat the above steps to add multiple widgets, each widget can use a different link, which can display the status of different servers. You need to config urls (Step 4) likes: {"17": "https://example.com/status", "18": "https://xxx.xx/status"}
Clone this wiki locally