Skip to content
lollipopkit🏳️‍⚧️ edited this page Jul 18, 2024 · 15 revisions

English | 简体中文

为了完整利用本项目的功能,你需要进行如下几步:

配置

关于应用配置,请参考 App Wiki。

Docker compose

安装并运行

version: "3.0"
services:
  srvbox:
    image: lollipopkit/srvbox_monitor:latest
    container_name: srvbox
    ports:
      - 3770:3770
    volumes:
      - ./config:/root/.config/server_box
    environment:
      - TZ=Asia/Shanghai
      # 自定义监听地址
      # - SBM_ADDR=0.0.0.0:3770
      # TLS 证书
      # - SBM_TLS_CRT=/root/.config/server_box/cert.pem
      # TLS 私钥
      # - SBM_TLS_KEY=/root/.config/server_box/key.pem

注意

  • 为了确保服务端能够正常读取网络接口,你需要确保 network_modehost
  • 请根据实际情况修改上述配置。
  • 如果 3770 端口被占用,你可以修改 SBM_ADDR 为其他端口。

选择你喜欢的目录,将上述内容写入 docker-compose.yml 并执行 docker compose up -d 即可。

更新

  • docker rm srvbox -f && docker rmi lollipopkit/srvbox_monitor:latest 删除旧的镜像
  • 然后 docker compose up -d 安装并运行即可。

一键脚本

下面的脚本需要 root 权限 (如果你不想使用 root 权限,请使用其他安装方式),自动安装最新版本,并配置 systemd

安装

curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -x -s -- install

卸载

curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -x -s -- uninstall

更新

curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -x -s -- upgrade

可执行文件

安装

  • 如果你有安装 go, go install github.com/lollipopkit/server_box_monitor@latest
  • 或者从 发布 下载

运行

如果你使用的是可执行文件,你大概率希望它能够持续运行,推荐使用 systemd

  • 示例文件(请阅读文件中的注释!):
    [Unit]
    Description=ServerBox Monitor Service
    After=network.target
    
    [Service]
    Type=simple
    # 如果想指定运行用户,取消下一行的注释并修改用户名
    # User=root
    Restart=on-failure
    RestartSec=5s
    # 请修改为你的可执行文件路径,或将可执行文件放到此处
    ExecStart=/usr/bin/server_box_monitor
    # /home/xxx 为你的家目录
    WorkingDirectory=/home/xxx/.config/server_box
    
    [Install]
    WantedBy=default.target
    
  • 非 root
    • 复制示例文件到 ~/.config/systemd/user/srvbox.service
    • systemctl --user enable --now srvbox
    • sudo loginctl enable-linger $USER 让服务在注销后继续运行.
  • root
    • 复制示例文件到 /etc/systemd/system/srvbox.service
    • 取消 User 行注释
    • systemctl enable --now srvbox

确认运行

在下一节之前,你需要确认服务端已经运行,你可以通过以下方式确认:

  • 如果你使用的是 Docker: docker logs srvbox
  • 如果使用的 systemd: systemctl status srvbox (可能需要加 sudo
  • 网页访问 http://DEVICE_IP:3770/status (如果你修改了监听地址,请自行替换)

如果有类似下方的显示,这代表服务已成功运行,可以继续下一步。 网页显示

修改监听配置

不同的安装方式,配置文件在不同路径:

  • 可执行文件: ~/.config/server_box/config.json
  • Docker: ./config/config.json

如下是一份完整的服务端配置示例,你需要根据自身需要进行修改:

{
    "version": 2,
    // 时间间隔,用于检查服务器状态
    // 默认: 7s
    // 大于 10s 的值将被忽略
    "interval": "7s",
    // 推送速率限制
    // 示例: 3/1m (每分钟三次), 1/10s (10秒一次)
    // 速率太低,消息可能严重滞后
    "rate": "1/10s",
    // 本机名称
    "name": "Server 1",
    // 监测规则
    // 可用类型(type): cpu, mem, net, disk, temp (温度), swap
    //
    // 阈值(Threshold)
    // 格式: 比较符号 值 单位
    // 比较符号: >, >=, <, <=, =
    // 值: int/float: 0.1 1 1.1
    // 单位: % (百分比), m/s (速度), m (大小), c (摄氏度)
    // 速度仅支持以秒为单位: b/s k/s, m/s, g/s ...
    // 
    // 匹配器:
    // 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": [
        // 当所有CPU的使用率超过 77.7% 时, 将会推送
        {
            "type": "cpu",
            "threshold": ">=77.7%",
            // "" / "cpu" -> 所有CPU, 这种情况下, 你可以省略该规则的 "matcher" 属性
            // "X" / "cpuX" -> 第X个CPU
            "matcher": "0"
        },
        // 当 eth0 网络接口的 上行 + 下行 速度超过 7.7m/s 时, 将会推送
        {
            "type": "net",
            // 速度仅支持以秒为单位
            "threshold": ">=7.7m/s",
            // 网络接口名
            // 可在 接口名后 + "-in" / "-out" 来分别获取下行/上行速度
            // 如果为空,则匹配所有网络接口
            "matcher": "eth0"
        },
        // 当 x86_pkg_temp 温度超过 37.7 摄氏度时, 将会推送
        {
            "type": "temp",
            // 温度仅支持摄氏度
            "threshold": ">=37.7c",
            // 你可以运行 `cat /sys/class/thermal/thermal_zone*/type` 来获取所有的温度类型
            "matcher": "x86_pkg_temp"
        },
        // 当 /dev/sda1 使用率超过 77.7% 时, 将会推送
        {
            "type": "disk",
            "threshold": ">=77.7%",
            // 挂载点或文件系统
            // 你可以使用 `df -h` 来获取所有有效的匹配器
            // 如果你使用的是 `docker`,请在容器内部运行 `df -h` 来获取所有有效的匹配器
            "matcher": "/dev/sda1"
        },
        // 当内存空闲率低于 17.7% 时, 将会推送
        {
            "type": "mem",
            // 支持: 大小, 百分比
            "threshold": "<=17.7%",
            // 支持: free, used, avail
            "matcher": "free"
        },
        // 当 swap 使用率超过 37.7% 时, 将会推送
        {
            "type": "swap",
            // 支持: 大小, 百分比
            "threshold": ">=37.7%",
            // 支持: free, used
            "matcher": "used"
        }
    ],
    // 推送规则
    //
    // 类型 type: webhook, ios, server酱 (以后有更多)
    // 接口 iface: 推送类型的接口
    // body_regex: 正则表达式匹配响应体
    // code: 响应码匹配
    //
    // 格式化参数:
    // "{{msg}}" 将被替换为监测结果
    // "{{name}}" 将被替换为本机名称
    "pushes": [
        {
            // 这是一个推送到QQ群的例子
            "type": "webhook",
            "name": "QQ Group",
            "iface": {
                // web钩子链接
                "url": "http://localhost:5700",
                // 请求头
                "headers": {
                    "Authorization": "Bearer YOUR_TOKEN",
                    "Content-Type": "application/json"
                },
                // 大写的HTTP方法
                "method": "POST",
                // 请求体
                // {{msg}} 和 {{name}} 将被替换为监测结果 和 本机名称
                "body": {
                    "action": "send_group_msg",
                    "params": {
                        "group_id": 123456789,
                        "message": "{{name}} 提示\n{{msg}}"
                    }
                },
                // 推送校验:
                // 如果 regex 和 code 未空,将不会检查响应体和响应码
                //
                // 如果响应体匹配,推送将被认为成功
                "body_regex": ".*",
                // 如果响应码匹配,推送将被认为成功
                "code": 200
            }
        },
        {
            "type": "ios",
            "name": "ServerBox",
            "iface": {
                // 你可以从 ServerBox iOS app 的 设置页 中获取 token
                "token": "YOUR_TOKEN",
                "title": "{{name}} 提示",
                "content": "{{msg}}",
                "body_regex": ".*",
                "code": 200
            }
        },
        {
            "type": "server_chan",
            "name": "Server酱",
            "iface": {
                // 具体配置请参考 https://sct.ftqq.com/
                "sckey": "YOUR_SCKEY",
                "title": "{{name}} 提示",
                "desp": "{{msg}}",
                "body_regex": ".*",
                "code": 200
            }
        },
        {
            "type": "bark",
            "name": "Bark",
            "iface": {
                // 具体配置请参考 https://github.com/Finb/Bark

                // 不填 / 留空 / 删除该键值 => 默认为 https://api.day.app
                "server": "",
                "key": "YOUR KEY",
                "title": "{{name}} 提示",
                "body": "{{msg}}",
                // 可选参数值
                // active:不设置时的默认值,系统会立即亮屏显示通知。
                // timeSensitive:时效性通知,可在专注状态下显示通知。
                // passive:仅将通知添加到通知列表,不会亮屏提醒
                "level": "timeSensitive",
                "body_regex": ".*",
                "code": 200
            }
        }
    ]
}
Clone this wiki locally