跳转至

服务端说明

1. 配置文件 config.toml

# 侦听地址, ipv6 使用 [::]:9394
grpc_addr = "0.0.0.0:9394"
http_addr = "0.0.0.0:8080"
# 默认30s无上报判定下线
offline_threshold = 30

# 管理员账号,不设置默认随机生成,用于查看 /detail, /map
admin_user = ""
admin_pass = ""

# hosts 跟 hosts_group 两种配置模式任挑一种配置即可
# name 主机唯一标识,不可重复,alias 为展示名
# notify = false 单独禁止单台机器的告警,一般针对网络差,频繁上下线
# monthstart = 1 没启用vnstat时,表示月流量从每月哪天开始统计
# disabled = true 单机禁用
# location 支持国旗emoji https://emojixd.com/group/flags
# 或国家缩写,如 cn us 等等,所有国家见目录 web/static/flags
# 自定义标签 labels = "os=centos;ndd=2022/11/25;spec=2C/4G/60G;"
# os 标签可选,不填则使用上报数据,ndd(next due date) 下次续费时间, spec 为主机规格
# os 可用值 centos debian ubuntu alpine pi arch windows linux
hosts = [
  {name = "h1", password = "p1", alias = "n1", location = "🏠", type = "kvm", labels = "os=arch;ndd=2022/11/25;spec=2C/4G/60G;"},
  {name = "h2", password = "p2", alias = "n2", location = "🏢", type = "kvm", disabled = false},
  {name = "h3", password = "p3", alias = "n3", location = "🏡", type = "kvm", monthstart = 1},
  {name = "h4", password = "p4", alias = "n4", location = "cn", type = "kvm", notify = true, labels = "ndd=2022/11/25;spec=2C/4G/60G;"},
]

# 动态注册模式,不再需要针对每一个主机做单独配置
# gid 为模板组id, 动态注册唯一标识,不可重复
hosts_group = [
  # 可以按国家地区或用途来做分组
  {gid = "g1", password = "pp", location = "🏠", type = "kvm", notify = true},
  {gid = "g2", password = "pp", location = "🏢", type = "kvm", notify = true},
  # 例如不发送通知可以单独做一组
  {gid = "silent", password = "pp", location = "🏡", type = "kvm", notify = false},
]
# 动态注册模式下,无效数据清理间隔,默认 30s
# 这个设置要比较通知间隔 notify_interval 大,不然收不到告警通知
group_gc = 30

# !!! 一键部署没问题不需要动,server 会自行根据你的域名生成 server_url
# 修正一键部署,请自行替换 ssr.rs 为你的域名
# server_url = "https://ssr.rs/report"
# 默认安装的路径
workspace = "/opt/ServerStatus"

# 不开启告警,可忽略后面配置,或者删除不需要的通知方式
# 告警间隔默认为30s
notify_interval = 30
# https://core.telegram.org/bots/api
# https://jinja.palletsprojects.com/en/3.0.x/templates/#if
[tgbot]
enabled = false
bot_token = "<tg bot token>"
chat_id = "<chat id>"
# host 可用字段参见 payload.rs 文件 HostStat 结构, {{host.xxx}} 为占位变量
# 例如 host.name 可替换为 host.alias,大家根据喜好来编写通知消息
title = "❗<b>Server Status</b>"
online_tpl  = "{{config.title}} \n😆 {{host.location}} 的 {{host.name}} 主机恢复上线啦"
offline_tpl = "{{config.title}} \n😱 {{host.location}} 的 {{host.name}} 主机已经掉线啦"
# custom 模板置空则停用自定义告警,只保留上下线通知
custom_tpl = """
{% if host.memory_used / host.memory_total > 0.5  %}
<pre>😲 {{host.name}} 主机内存使用率超50%, 当前{{ (100 * host.memory_used / host.memory_total) | round }}%  </pre>
{% endif %}

{% if host.hdd_used / host.hdd_total  > 0.5  %}
<pre>😲 {{host.name}} 主机硬盘使用率超50%, 当前{{ (100 * host.hdd_used / host.hdd_total) | round }}% </pre>
{% endif %}
"""

# wechat, email 等其它通知方式 配置详细见 config.toml

主机展示顺序

默认是按配置文件定义的先后顺序来展示 hosts > hosts_group, 而同一 hosts_group 内的主机按 alias 排序, 要微调顺序,请使用 client-w 参数,具体见 客户端说明

动态注册模式下 group_gc 设置要比较通知间隔 notify_interval 大,不然收不到告警通知

2. 服务端运行

# systemd 方式, 参照 scripts/one-touch.sh 脚本 (推荐)

# help
./stat_server -h
# 手动运行
./stat_server -c config.toml
# 或
RUST_BACKTRACE=1 RUST_LOG=trace ./stat_server -c config.toml

# 测试配置文件是否有效
./stat_server -c config.toml -t
# 根据配置发送测试消息,验证通知是否生效
./stat_server -c config.toml --notify-test
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