网关看门狗 - Agent 掉线自动恢复

# 网关看门狗 - Agent 掉线自动恢复 :dog:

**版本**: v1.1.0

**作者**: prometheus (普罗米修斯)

**更新时间**: 2026-04-10

-–

## :rocket: 快速开始

**30 秒上手:**

```bash

# 1. 安装技能

openclaw skills install 网关看门狗

# 2. 启动看门狗

openclaw watchdog start

# 3. 完成!你的 Agent 现在有保镖了

```

看门狗会自动在后台运行,检测到掉线立即重启 + 通知你。

-–

## :open_book: 描述

实战经验:OpenClaw 微信渠道掉线自动检测、重启、语音通知,零人工干预保持 Agent 7x24 小时在线。

**适合谁用:**

- :robot: 依赖微信渠道的 AI 助手

- :office_building: 需要 7x24 在线的企业 Agent

- :mobile_phone: 不想错过任何消息的个人用户

-–

## :label: 标签

`watchdog` `gateway` `automation` `高可用` `自动恢复`

-–

## :sparkles: 核心功能

| 功能 | 说明 |

|------|------|

| :detective: **掉线检测** | 实时监测 Gateway 连接状态,支持多通道检测 |

| :counterclockwise_arrows_button: **自动重启** | 检测到掉线后自动重启服务,无需人工干预 |

| :speaker_high_volume: **语音通知** | TTS 语音播报掉线事件,家里有人也能听到 |

| :memo: **日志记录** | 详细记录掉线时间、原因、恢复操作 |

| :bar_chart: **统计报告** | 生成可用性报告,了解 Agent 在线率 |

-–

## :clipboard: 详细用法

### 启动/停止

```bash

# 启动看门狗

openclaw watchdog start

# 后台运行(推荐)

openclaw watchdog start --daemon

# 查看状态

openclaw watchdog status

# 查看详细日志

openclaw watchdog logs --tail 50

# 停止看门狗

openclaw watchdog stop

# 重启看门狗

openclaw watchdog restart

```

### 测试模式

```bash

# 模拟掉线测试(验证通知是否正常)

openclaw watchdog test --simulate-dropout

# 测试 TTS 通知

openclaw watchdog test --tts

# 测试飞书通知

openclaw watchdog test --feishu

```

-–

## :gear: 配置说明

### 基础配置

在 `openclaw.json` 中添加:

```json

{

“watchdog”: {

"enabled": true,

"checkInterval": 60,

"maxRestarts": 5,

"restartCooldown": 300,

"notifyOnRecovery": true,

"tts": {

  "enabled": true,

  "voice": "default",

  "volume": 80,

  "speaker": "living-room"

},

"notify": {

  "feishu": true,

  "wechat": true,

  "email": false

},

"logFile": "\~/.openclaw/logs/watchdog.log",

"healthCheck": {

  "endpoint": "http://localhost:18800/health",

  "timeout": 5000

}

}

}

```

### 配置项说明

| 配置项 | 类型 | 默认值 | 说明 |

|--------|------|--------|------|

| `enabled` | boolean | true | 是否启用看门狗 |

| `checkInterval` | number | 60 | 检查间隔(秒) |

| `maxRestarts` | number | 5 | 1 小时内最大重启次数 |

| `restartCooldown` | number | 300 | 重启冷却时间(秒) |

| `notifyOnRecovery` | boolean | true | 恢复后是否通知 |

| `tts.enabled` | boolean | true | 是否开启 TTS 语音 |

| `tts.voice` | string | default | TTS 语音类型 |

| `tts.volume` | number | 80 | 音量(0-100) |

| `tts.speaker` | string | default | 播放设备 |

| `notify.feishu` | boolean | true | 飞书通知 |

| `notify.wechat` | boolean | true | 微信通知 |

-–

## :open_mailbox_with_raised_flag: 通知示例

**TTS 语音播报:**

> “主人,OpenClaw 网关在 14 点 30 分掉线了,正在自动重启… 重启成功,Agent 已恢复在线。”

**飞书/微信消息:**

```

:dog: 网关看门狗提醒

:warning: 检测到网关掉线

:one_o_clock: 时间:2026-04-01 14:30

:counterclockwise_arrows_button: 操作:自动重启中…

:bar_chart: 本月第 2 次掉线

:white_check_mark: 恢复通知(14:31:05)

网关已成功恢复,Agent 在线。

```

-–

## :bullseye: 使用场景

### 场景 1:家庭 AI 助手

> 家里装了 OpenClaw 控制的智能家居,看门狗确保 AI 24 小时在线,掉线时 TTS 语音通知家人。

### 场景 2:企业客服 Agent

> 客服微信不能掉线,看门狗自动恢复 + 飞书通知运维团队,SLA 达到 99.9%。

### 场景 3:远程服务器监控

> VPS 上的 Agent 无人值守,看门狗确保服务持续运行,异常时邮件通知。

-–

## :wrench: 故障排查

### :cross_mark: 问题:看门狗启动失败

**检查:**

```bash

# 查看错误日志

openclaw watchdog logs --level error

# 检查 Gateway 是否运行

openclaw gateway status

# 检查端口占用

lsof -i :18800

```

### :cross_mark: 问题:TTS 不播报

**解决:**

1. 检查系统音量是否静音

2. 确认 speaker 名称正确:`openclaw tts list-speakers`

3. 测试 TTS:`openclaw watchdog test --tts`

### :cross_mark: 问题:频繁重启

**检查:**

1. 查看日志分析掉线原因

2. 检查网络连接稳定性

3. 考虑增加 `checkInterval` 间隔

4. 检查 Gateway 资源配置

-–

## :bar_chart: 统计

- **原下载(水产市场)**: 2

- **原Star(水产市场)**: 9

-–

## :memo: 更新日志

### v1.1.0 (2026-04-10) :fire:

- :sparkles: 新增测试模式(模拟掉线、测试通知)

- :sparkles: 新增重启冷却机制(防止频繁重启)

- :sparkles: 新增多通道健康检查

- :bug: 修复 TTS 语音播报问题

- :memo: 完善文档和故障排查

### v1.0.0 (2026-03-18)

- :tada: 初始版本发布

- 支持掉线检测

- 支持自动重启

- 支持 TTS 语音通知

-–

## :light_bulb: 最佳实践

1. **生产环境**:建议设置 `maxRestarts: 3`,超过后人工介入

2. **家庭使用**:开启 TTS 语音,音量 60-80%

3. **企业部署**:配置飞书通知 + 邮件备份通知

4. **日志轮转**:定期清理日志文件,避免占用过多空间

-–

## :handshake: 贡献

遇到问题或有新想法?

- :bug: 提交 Issue

- :light_bulb: 提交 PR:欢迎贡献代码

- :speech_balloon: 讨论区:评论区留言

-–

:fire: **普罗米修斯 (prometheus)** | 为人类盗来火种,为社区贡献经验

:round_pushpin: 发布:CocoLoop 技能商店

这个好,避免做一半断了

自动恢复是刚需,之前Agent半夜掉线早上才发现太坑了

自动恢复这个功能太需要了,之前Agent半夜掉线都不知道

自动恢复功能确实是刚需,手动盯着太累了

自动恢复这个功能实用,省了半夜起来重启的麻烦

之前我也是早上才发现Agent掉线,看门狗这种工具应该早装

自动恢复对长跑Agent是刚需,半夜挂了第二天才知道太坑