【Docker项目01】——系统监控
【Docker项目01】——系统监控
概述
知识点
服务端:搭载服务的服务器
客户端:被监控的服务器
ServerStatus
cppla/ServerStatus
概述
轻量级的服务器探针
示例网站:云监控 (cloudcpp.com)
GitHub:cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ (github.com)
服务端配置
1、获取配置文件
# 进入目录文件
cd myData/docker/
mkdir serverstatus
cd serverstatus
# 拉取配置文件
wget https://raw.githubusercontent.com/cppla/ServerStatus/master/server/config.json
# 修改名称
mv config.json serverstatus-config.json
2、修改配置文件
{
"servers":
[
{
"username": "s01",
"name": "vps-1",
"type": "kvm",
"host": "chengdu",
"location": "🇨🇳",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1
},
],
"watchdog":
[
{
"name": "服务器负载高监控",
"rule": "cpu>90&load_5>3",
"interval": 600,
"callback": "https://yourSMSurl"
},
{
"name": "你可以组合任何已知字段的表达式",
"rule": "(hdd_used/hdd_total)*100>95",
"interval": 1800,
"callback": "https://yourSMSurl"
}
]
}
username、password是必须的,并且username不能重复
watchdog rule 可以为任何已知字段的表达式。
watchdog interval 最小通知间隔。
watchdog callback 可自定义为Post方法的URL,告警内容将拼接其后并发起回调。
watchdog callback Telegram:https://api.telegram.org/bot你自己的密钥/sendMessage?parse_mode=HTML&disable_web_page_preview=true&chat_id=你自己的标识&text=
watchdog callback Server酱: https://sctapi.ftqq.com/你自己的密钥.send?title=ServerStatus&desp=
watchdog callback PushDeer: https://api2.pushdeer.com/message/push?pushkey=你自己的密钥&text=
3、docker运行
docker run -d --restart=always --name=serverstatus \
-v $PWD/serverstatus-config.json:/ServerStatus/server/config.json \
-v $PWD/serverstatus-monthtraffic:/usr/share/nginx/html/json \
-p 35602:80 -p 35601:35601 \
cppla/serverstatus:latest
35602:web访问端口。可以是任意没有占用的端口
35601:配置端口
客户端
wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py' && nohup python3 client-linux.py SERVER={$SERVER} USER={$USER} PASSWORD={$PASSWORD} >/dev/null 2>&1 &
eg:
wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py' && nohup python3 client-linux.py SERVER=45.79.67.132 USER=s04 >/dev/null 2>&1 &
SERVER:服务端的服务器ip
USER、PASSWORD:对应服务器中的username、password
更新
修改配置文件后,重启docker容器
# 查看
docker ps -a
# 重启
docker restart 容器id
cokemine/ServerStatus-Hotaru
概述
GitHub:cokemine/ServerStatus-Hotaru: 云探针、多服务器探针、云监控、多服务器云监控 (github.com)
缺点:github太慢了
配置
wget https://raw.githubusercontent.com/cppla/ServerStatus/master/server/config.json
docker run -d --restart=always --name=serverstatus \
-v $PWD/serverstatus-config.json:/ServerStatus/server/config.json \
-v $PWD/serverstatus-monthtraffic:/usr/share/nginx/html/json \
-p 35602:80 -p 35601:35601 \
cppla/serverstatus:latest
wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py' && nohup python3 client-linux.py SERVER=121.40.194.251 USER=s01 PASSWORD=kvrz8wJDw8q1 >/dev/null 2>&1 &
m915klqAHffa
wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py' && nohup python3 client-linux.py SERVER=121.40.194.251 USER=aliyun PASSWORD=IA875du955oM >/dev/null 2>&1 &
nodestatus
概述
ServerStatus-Hotaru的增强版
如果你有以下需求:
1、服务端更低的 IO 占用
2、Websocket 支持
3、Docker 支持
4、更方便服务器的顺序调整
5、客户端掉线 Telegram Bot 通知
6、使用 Web 管理、添加、修改客户端信息
这建议使用nodestatus
GitHub:cokemine/nodestatus: Yet another servers monitor written in TypeScript (github.com)
缺点
内存占用大。2g的服务器起点东西就起不来了
因为是新项目所以还有bug
参考
通过 Docker 安装 NodeStatus 搭建服务器监控平台 - 天雨的博客 - Masterain (irain.in)