ServerStatus-Rust | 简洁美观的服务器
本文发布于334天前,最后更新于312天前,其中的信息可能有所发展或是发生改变。如有疑问请联系邮箱:admin@yemengstar.com。

1.前言

Rust 版 ServerStatus 云探针

项目地址:zdz/ServerStatus-Rust: ✨ Rust 版 ServerStatus 探针、威力加强版 (github.com)

2.快速体验

# for CentOS/Debian/Ubuntu x86_64
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/one-touch.sh'
bash -ex one-touch.sh
# 部署完毕,打开 http://127.0.0.1:8080/ 或 http://<你的IP>:8080/
# 自定义部署可参照 one-touch.sh 脚本

3.统一管理

# 下载脚本
wget --no-check-certificate -qO status.sh 'https://raw.githubusercontent.com/zdz/ServerStatus-Rust/master/status.sh'

# 安装 服务端
bash status.sh -i -s

# 安装 客户端
bash status.sh -i -c
# or
bash status.sh -i -c protocol://username:password@master:port
# eg:
bash status.sh -i -c grpc://h1:p1@127.0.0.1:9394
bash status.sh -i -c http://h1:p1@127.0.0.1:8080

# 更多用法:
❯ bash status.sh

help:
    -i,--install    安装 Status
        -i -s           安装 Server
        -i -c           安装 Client
        -i -c conf      自动安装 Client
    -up,--upgrade   升级 Status
        -up -s          升级 Server
        -up -c          升级 Client
        -up -a          升级 Server和Client
    -un,--uninstall  卸载 Status
        -un -s           卸载 Server
        -un -c           卸载 Client
        -un -a           卸载 Server and Client
    -rc,--reconfig      更改 Status 配置
        -rc          更改 Client 配置
        -rc conf         自动更改 Client配置
    -s,--server     管理 Status 运行状态
        -s {status|start|stop|restart}
    -c,--client     管理 Client 运行状态
        -c {status|start|stop|restart}
    -b,--bakup      备份 Status
        -b -s          备份 Server
        -b -c          备份 Client
        -b -a          备份 Server and Client
    -rs,--restore    恢复 Status
        -rs -s          恢复 Server
        -rs -c          恢复 Client
        -rs -a          恢复 Server and Client
    -h,--help       查看帮助
若无法访问 Github: 
    CN=true bash status.sh args

4.服务端说明

4.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
group_gc = 30

# 不开启告警,可忽略后面配置,或者删除不需要的通知方式
# 告警间隔默认为30s
notify_interval = 30
# https://core.telegram.org/bots/api
# https://jinja.palletsprojects.com/en/3.0.x/templates/#if
[tgbot]
# 开关 true 打开
enabled = false
bot_token = "<tg bot token>"
chat_id = "<chat id>"
# host 可用字段见 payload.rs 文件 HostStat 结构, {{host.xxx}} 为占位变量
# 例如 host.name 可替换为 host.alias,大家根据自己的喜好来编写通知消息
# {{ip_info.query}} 主机 ip,  {{sys_info.host_name}} 主机 hostname
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, webhook 等其它通知方式 配置详细见 config.toml

4.2 服务端运行

# systemd 方式, 参照 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

# 🐳 docker 方式
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

5.客户端说明

# 公网环境建议 headscale/nebula 组网或走 https, 使用 nginx 对 server 套 ssl 和自定义 location /report
# alpine linux 需要安装相关命令 apk add procps iproute2 coreutils
# 如果 Rust 版客户端在你的系统无法使用,请切换到下面 4.2 Python 跨平台版本

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

# 💪 手动方式
# Rust 版本 Client
./stat_client -h
./stat_client -a "http://127.0.0.1:8080/report" -u h1 -p p1
# 或
./stat_client -a "grpc://127.0.0.1:9394" -u h1 -p p1

# rust client 可用参数
./stat_client -h
OPTIONS:
    -6, --ipv6                   ipv6 only, default:false
    -a, --addr <ADDR>            [default: http://127.0.0.1:8080/report]
        --alias <ALIAS>          alias for host [default: unknown]
        --cm <CM_ADDR>           China Mobile probe addr [default: cm.tz.cloudcpp.com:80]
        --ct <CT_ADDR>           China Telecom probe addr [default: ct.tz.cloudcpp.com:80]
        --cu <CU_ADDR>           China Unicom probe addr [default: cu.tz.cloudcpp.com:80]
        --disable-extra          disable extra info report, default:false
        --disable-notify         disable notify, default:false
        --disable-ping           disable ping, default:false
        --disable-tupd           disable t/u/p/d, default:false
    -g, --gid <GID>              group id [default: ]
    -h, --help                   Print help information
        --ip-info                show ip info, default:false
        --ip-source <IP_SOURCE>  ip info source [env: SSR_IP_SOURCE=] [default: ip-api.com]
        --sys-info               show sys info, default:false
        --json                   use json protocol, default:false
        --location <LOCATION>    location [default: ]
    -n, --vnstat                 enable vnstat, default:false
        --vnstat-mr <VNSTAT_MR>  vnstat month rotate 1-28 [default: 1]
    -p, --pass <PASS>            password [default: p1]
    -t, --type <HOST_TYPE>       host type [default: ]
    -u, --user <USER>            username [default: h1]
    -V, --version                Print version information
    -w, --weight <WEIGHT>        weight for rank [default: 0]

# 一些参数说明
--ip-info       # 显示本机ip信息后立即退出,目前使用 ip-api.com 数据
--ip-source     # 指定 ip 信息源,ip-api.com / ip.sb / ipapi.co / myip.la
--sys-info      # 显示本机系统信息后立即退出
--disable-extra # 不上报系统信息和IP信息
--disable-ping  # 停用三网延时和丢包率探测
--disable-tupd  # 不上报 tcp/udp/进程数/线程数,减少CPU占用
-w, --weight    # 排序加分,微调让主机靠前显示,无强迫症可忽略
-g, --gid       # 动态注册的组id
--alias         # 动态注册模式下,指定主机的展示名字
# 总流量,网卡流量/网速统计
-i, --iface         # 非空时,只统计指定网口
-e, --exclude-iface # 排除指定网口,默认排除 "lo,docker,vnet,veth,vmbr,kube,br-"
本文为夜梦星尘原创文章。
文章作者:夜梦星尘
文章链接:ServerStatus-Rust | 简洁美观的服务器
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自夜梦星尘
支持作者:夜梦星尘的爱发电
上一篇
下一篇