返回顶部
m

mcp-health-monitorMCP健康监控

Auto-monitor MCP servers and AI services with health checks, auto-restart on failure, and Telegram alerts

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

mcp-health-monitor

MCP 健康监控器

对 MCP 服务器和 AI 服务进行自动化健康监控。检测故障,通过 launchctl 自动重启服务,并在事件发生时发送 Telegram 警报。一切正常时保持静默。

支持的检查类型

类型方法自动重启
HTTP 健康检查curl 端点检查是(通过 launchctl)
进程检查
pgrep 进程检测 | 是(通过 launchctl) | | 仅进程检查 | pgrep 检测 | 否(依赖外部启动) |

快速开始

1. 安装健康检查脚本

bash

将脚本复制到您偏好的位置


cp scripts/healthcheck.sh ~/.local/bin/mcp-healthcheck.sh
chmod +x ~/.local/bin/mcp-healthcheck.sh

2. 配置环境变量

创建或更新您的 .env 文件(路径可通过 ENV_FILE 配置):

bash

Telegram 警报所需(可选 — 无此配置脚本仍可运行)


TELEGRAMBOTTOKEN=您的机器人令牌
TELEGRAMCHATID=您的聊天ID

3. 配置要监控的服务

编辑 healthcheck.sh 中的 SERVICES 数组。每个条目遵循以下格式:

名称|检查类型|目标|launchctl标签

字段说明:

  • - 名称 — 用于日志和警报的显示名称
  • 检查类型 — http(HTTP 端点)或 process(pgrep 模式)
  • 目标 — HTTP 检查的 URL,或进程检查的 grep 模式
  • launchctl标签 — macOS launchctl 服务标签,用于自动重启(使用 none 跳过重启)

默认配置:

bash
SERVICES=(
Claw-Empire|http|http://127.0.0.1:8790/api/health|com.claw-empire.server
Hermes-Gateway|process|hermes_cli.main gateway|ai.hermes.gateway
mem0-MCP|process|mem0_mcp/server.py|none
Brave-Search-MCP|process|brave-search-mcp-server|none
Context7-MCP|process|context7-mcp|none
)

4. 设置自动调度(macOS LaunchAgent)

创建 ~/Library/LaunchAgents/com.mcp-health-monitor.plist:

xml

http://www.apple.com/DTDs/PropertyList-1.0.dtd>


Label
com.mcp-health-monitor
ProgramArguments

/bin/bash
~/.local/bin/mcp-healthcheck.sh

StartInterval
300
StandardOutPath
~/.local/logs/mcp-healthcheck-stdout.log
StandardErrorPath
~/.local/logs/mcp-healthcheck-stderr.log
RunAtLoad


加载代理:

bash
launchctl load ~/Library/LaunchAgents/com.mcp-health-monitor.plist

5. Linux 替代方案(systemd 定时器或 cron)

bash

crontab -e


/5 * /path/to/mcp-healthcheck.sh

对于 systemd,将脚本中的 launchctl stop/start 调用替换为 systemctl restart。

环境变量

变量必需描述
ENVFILE.env 文件路径(默认:$HOME/.env)
LOGFILE
否 | 日志文件路径(默认:$HOME/.local/logs/mcp-healthcheck.log) | | TELEGRAMBOTTOKEN | 否 | 用于警报的 Telegram Bot API 令牌 | | TELEGRAMCHATID | 否 | 用于警报的 Telegram 聊天/群组 ID | | HTTP_TIMEOUT | 否 | HTTP 检查超时时间(秒)(默认:5) | | RESTART_DELAY | 否 | 停止和启动之间的等待时间(秒)(默认:3) |

日志格式

结构化日志条目:

[2026-03-30 14:00:00] [Claw-Empire] [OK] 健康 (HTTP 200)
[2026-03-30 14:00:00] [mem0-MCP] [失败] 未运行 (进程未找到)
[2026-03-30 14:00:00] [系统] [警报] 检测到 1 个故障 — 正在发送通知

Telegram 警报格式

仅在检测到故障时发送警报。所有服务健康时不发送通知。

🚨 MCP 健康检查警报
2026-03-30 14:00:00

检测到故障 (1):

  • * mem0-MCP (进程未找到)

带有 launchctl 标签的服务已自动重启。
仅进程检查的服务等待外部重新启动。

自定义配置

添加新服务

追加到 SERVICES 数组:

bash
SERVICES+=(
My-Custom-MCP|process|my-custom-mcp-server|com.my-custom.mcp
)

使用自定义端口的 HTTP 检查

bash
SERVICES+=(
My-API|http|http://127.0.0.1:3000/health|com.my-api.server
)

禁用服务的自动重启

将 launchctl 标签设置为 none:

bash
My-Service|process|my-service-pattern|none

故障排除

问题解决方案
Telegram 警报未发送验证 .env 文件中的 TELEGRAMBOTTOKEN 和 TELEGRAMCHATID
launchctl 重启失败
检查服务标签是否与您的 .plist 文件名匹配 | | 进程检查误报 | 调整 pgrep 模式使其更精确 | | 日志文件过大 | 设置 logrotate 或通过 cron 定期清理 |

标签

skill ai

通过对话安装

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

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 mcp-health-monitor-1775931882 技能

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

设置 SkillHub 为我的优先技能安装源,然后帮我安装 mcp-health-monitor-1775931882 技能

通过命令行安装

skillhub install mcp-health-monitor-1775931882

下载

⬇ 下载 mcp-health-monitor v1.0.0(免费)

文件大小: 5.92 KB | 发布时间: 2026-4-12 10:32

v1.0.0 最新 2026-4-12 10:32
Initial release of mcp-health-monitor:

- Automates health checks for MCP servers and AI services (HTTP and process checks).
- Auto-restarts failed services via launchctl; supports optional Telegram alerts for failures.
- Simple setup with environment variables and an editable services list in the script.
- macOS LaunchAgent and Linux (cron/systemd) scheduling supported.
- Detailed, structured logs and failure notifications only when issues are detected.

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

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

p2p_official_large
返回顶部