返回顶部
s

server-watchdog服务器监控

Monitor remote servers via SSH — check service health (PM2, systemd, Docker), database status (MongoDB, MySQL, PostgreSQL), disk space, memory, and auto-restart crashed services. Sends alerts via messaging. Use when asked to check server status, monitor services, restart crashed processes, or set up server health checks.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
167
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

server-watchdog

服务器看门狗

通过SSH监控并自动修复远程服务器。检查服务、数据库、磁盘、内存——重启故障项,报告异常项。

前置条件

  • - 目标服务器的SSH访问权限(密码或密钥认证)
  • 本地安装expect(用于密码认证SSH)
  • 目标服务器运行PM2、systemd或Docker进行服务管理

快速参考

检查PM2服务

bash ssh user@host pm2 list ssh user@host pm2 logs --lines 20 --nostream

检查MongoDB

bash

Windows

ssh user@host net start | findstr MongoDB ssh user@host powershell -Command \(Test-NetConnection -ComputerName 127.0.0.1 -Port 27017).TcpTestSucceeded\

Linux

ssh user@host systemctl status mongod ssh user@host mongosh --eval db.runCommand({ping:1}) --quiet

检查磁盘与内存

bash

Linux

ssh user@host df -h && free -h

Windows

ssh user@host powershell -Command \Get-PSDrive -PSProvider FileSystem | Select Root,Used,Free; \$os=Get-CimInstance Win32_OperatingSystem; Write-Output (RAM: +[math]::Round((\$os.TotalVisibleMemorySize-\$os.FreePhysicalMemory)/1MB,1)+GB / +[math]::Round(\$os.TotalVisibleMemorySize/1MB,1)+GB)\

工作流程

  1. 1. 诊断 — SSH登录,检查服务状态、日志、磁盘、内存
  2. 识别 — 解析日志,查找错误、崩溃、内存溢出或非正常关闭
  3. 修复 — 重启崩溃的服务(pm2 restart、net start、systemctl restart)
  4. 验证 — 确认服务已恢复并正常响应
  5. 告警 — 通过消息通知用户并附上摘要

崩溃分析

当服务宕机时,按以下顺序检查:

  1. 1. 服务日志 — pm2 logs、journalctl -u service、Windows事件日志
  2. 应用日志 — 检查配置路径下的日志文件
  3. 系统事件 — OOM杀手、意外关机、磁盘已满
  4. 数据库日志 — MongoDB:检查mongod.log中的致命错误(s:F条目)

MongoDB崩溃模式

s:F — 致命错误(崩溃)
Unhandled exception — 内部错误(通常与FTDC相关)
Detected unclean shutdown — 进程被强制终止,未正常关闭
WiredTiger error — 存储引擎损坏

自动修复方案

PM2服务重启

bash pm2 restart pm2 save # 重启后持久化

MongoDB(Windows)

bash net stop MongoDB timeout /t 5 net start MongoDB

MongoDB(Linux)

bash sudo systemctl restart mongod

部署看门狗服务

如需持久监控,请部署附带的看门狗脚本:
  1. 1. 将scripts/mongodb-watchdog.js复制到目标服务器
  2. 安装:npm init -y && npm install mongodb
  3. 启动:pm2 start mongodb-watchdog.js --name mongodb-watchdog
  4. 保存:pm2 save

密码SSH(通过expect)

当密钥认证不可用时:
bash
expect -c set timeout 20
spawn ssh -o StrictHostKeyChecking=no user@host COMMAND
expect {
password: { send PASSWORD\r; exp_continue }
eof
}

告警模板

🚨 服务器告警 — [主机名]

⏰ 时间:[时间戳]
❌ 问题:[服务] 已宕机
📋 原因:[日志中的崩溃原因]
🔄 操作:已自动重启 [服务]
✅ 状态:[服务] 已恢复在线

📊 系统健康状态:
• 内存:X GB / Y GB
• 磁盘:Z% 已使用
• 服务:N/N 在线

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 server-watchdog-1776262994 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 server-watchdog-1776262994 技能

通过命令行安装

skillhub install server-watchdog-1776262994

下载

⬇ 下载 server-watchdog v1.0.0(免费)

文件大小: 6.83 KB | 发布时间: 2026-4-17 16:04

v1.0.0 最新 2026-4-17 16:04
Initial release

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部