| name | troubleshooting |
| description | OpenClaw 问题排查与诊断 |
| version | 1.0.0 |
| author | terminal-skills |
| tags | ["openclaw","troubleshooting","debug","diagnosis","monitoring"] |
OpenClaw 问题排查与诊断
概述
OpenClaw 常见问题的排查思路、诊断命令和解决方案。
健康检查
服务状态检查
curl -s http://localhost:8080/api/health | jq .
curl -s http://localhost:8080/api/health/detail | jq .
curl -s http://localhost:8080/api/status | jq .
集群状态
curl -s http://localhost:8080/api/cluster/info | jq .
curl -s http://localhost:8080/api/cluster/nodes | jq .
curl -s http://localhost:8080/api/workers | jq .
curl -s http://localhost:8080/api/workers | jq '.[] | select(.status == "ONLINE")'
日志分析
日志位置
tail -f /opt/openclaw/logs/openclaw-server.log
tail -f /opt/openclaw/logs/error.log
tail -f /opt/openclaw/logs/openclaw-worker.log
ls -la /opt/openclaw/logs/tasks/
docker logs -f openclaw-server
docker logs -f openclaw-worker --tail 100
日志搜索
grep -i "error\|exception\|failed" /opt/openclaw/logs/openclaw-server.log
grep "taskId=12345" /opt/openclaw/logs/openclaw-server.log
grep "2024-01-15 10:" /opt/openclaw/logs/openclaw-server.log
grep -oP 'Exception: \K[^:]+' /opt/openclaw/logs/error.log | sort | uniq -c | sort -rn
tail -f /opt/openclaw/logs/openclaw-server.log | grep -i --color "error\|exception"
日志级别调整
curl -X POST http://localhost:8080/api/admin/logging/level \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKEN}" \
-d '{"logger": "com.openclaw.scheduler", "level": "DEBUG"}'
curl http://localhost:8080/api/admin/logging/level \
-H "Authorization: Bearer ${TOKEN}"
数据库问题排查
连接问题
mysql -h localhost -u openclaw -p -e "SELECT 1"
mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected'"
mysql -u root -p -e "SHOW PROCESSLIST"
curl -s http://localhost:8080/api/admin/datasource/pool | jq .
mysql -u root -p -e "SHOW FULL PROCESSLIST" | grep -v Sleep
数据库性能
tail -f /var/log/mysql/slow.log
mysql -u root -p -e "
SELECT * FROM information_schema.INNODB_LOCK_WAITS;
SELECT * FROM information_schema.INNODB_LOCKS;
"
mysql -u root -p openclaw -e "SHOW TABLE STATUS"
mysql -u root -p openclaw -e "EXPLAIN SELECT * FROM task WHERE status = 'RUNNING'"
数据一致性检查
mysql -u root -p openclaw -e "
SELECT status, COUNT(*) as count
FROM task
GROUP BY status
"
mysql -u root -p openclaw -e "
SELECT t.* FROM task t
LEFT JOIN worker w ON t.worker_id = w.id
WHERE t.status = 'RUNNING' AND (w.id IS NULL OR w.status != 'ONLINE')
"
Redis 问题排查
连接检查
redis-cli -h localhost -p 6379 ping
redis-cli -h localhost -p 6379 info clients
redis-cli -h localhost -p 6379 info memory
redis-cli -h localhost -p 6379 slowlog get 10
缓存分析
redis-cli -h localhost -p 6379 keys "openclaw:*"
redis-cli -h localhost -p 6379 get "openclaw:task:12345"
redis-cli -h localhost -p 6379 hgetall "openclaw:worker:worker-1"
redis-cli -h localhost -p 6379 llen "openclaw:task:queue:default"
redis-cli -h localhost -p 6379 memory usage "openclaw:task:12345"
redis-cli -h localhost -p 6379 debug object "openclaw:task:12345"
任务执行问题
任务状态查询
curl -s http://localhost:8080/api/tasks/12345 | jq .
curl -s http://localhost:8080/api/tasks/12345/executions | jq .
curl -s "http://localhost:8080/api/tasks?status=FAILED&limit=10" | jq .
curl -s "http://localhost:8080/api/tasks?status=TIMEOUT&limit=10" | jq .
任务执行日志
curl -s http://localhost:8080/api/tasks/12345/log | jq .
cat /opt/openclaw/logs/tasks/12345.log
tail -f /opt/openclaw/logs/tasks/12345.log
常见任务问题
任务一直 Pending
curl -s http://localhost:8080/api/workers | jq '.[] | select(.status == "ONLINE")'
curl -s http://localhost:8080/api/workers | jq '.[] | {name, runningTasks, maxTasks}'
curl -s http://localhost:8080/api/admin/queue/status | jq .
curl -s http://localhost:8080/api/tasks/12345 | jq '.group'
curl -s http://localhost:8080/api/workers | jq '.[] | select(.group == "specific-group")'
任务执行超时
curl -s http://localhost:8080/api/tasks/12345 | jq '.timeout'
curl -s http://localhost:8080/api/tasks/12345/executions | jq '.[] | {startTime, endTime, duration}'
curl -X PUT http://localhost:8080/api/tasks/12345 \
-H "Content-Type: application/json" \
-d '{"timeout": 7200000}'
任务执行失败
curl -s http://localhost:8080/api/tasks/12345/executions | jq '.[-1] | {status, errorMessage, errorStack}'
curl -s http://localhost:8080/api/tasks/12345/executions | jq '. | length'
curl -X POST http://localhost:8080/api/tasks/12345/retry
Worker 问题排查
Worker 无法注册
tail -f /opt/openclaw/logs/openclaw-worker.log | grep -i "register\|connect"
telnet openclaw-server 9090
nc -zv openclaw-server 9090
grpcurl -plaintext localhost:9090 list
grep "worker" /opt/openclaw/logs/openclaw-server.log | tail -50
Worker 频繁离线
grep "heartbeat" /opt/openclaw/conf/worker.yml
ping -c 10 openclaw-server
top -p $(pgrep -f openclaw-worker)
free -h
df -h
jstat -gc $(pgrep -f openclaw-worker)
Worker 负载不均
curl -s http://localhost:8080/api/workers | jq '.[] | {name, runningTasks, completedTasks}'
curl -s http://localhost:8080/api/admin/config | jq '.scheduler.strategy'
curl -s http://localhost:8080/api/workers | jq '.[] | {name, weight}'
性能问题排查
CPU 高
top -H -p $(pgrep -f openclaw-server)
jstack $(pgrep -f openclaw-server) > thread_dump.txt
jstack $(pgrep -f openclaw-server) | grep -A 30 "RUNNABLE"
curl -s http://localhost:8080/api/admin/threadpool | jq .
内存问题
jstat -gc $(pgrep -f openclaw-server) 1000
jmap -dump:format=b,file=heapdump.hprof $(pgrep -f openclaw-server)
jmap -histo $(pgrep -f openclaw-server) | head -30
grep "GC" /opt/openclaw/logs/gc.log | tail -50
网络问题
ss -s
netstat -an | grep 8080 | wc -l
netstat -an | grep TIME_WAIT | wc -l
curl -o /dev/null -s -w "Connect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" http://localhost:8080/api/health
集群问题排查
主节点选举
curl -s http://localhost:8080/api/cluster/leader | jq .
grep "leader\|election" /opt/openclaw/logs/openclaw-server.log
curl -X POST http://localhost:8080/api/admin/cluster/reelect \
-H "Authorization: Bearer ${TOKEN}"
节点同步
curl -s http://localhost:8080/api/cluster/sync/status | jq .
curl -X POST http://localhost:8080/api/admin/cluster/sync \
-H "Authorization: Bearer ${TOKEN}"
诊断工具
内置诊断
curl -s http://localhost:8080/api/admin/diagnose | jq .
curl -s http://localhost:8080/api/admin/diagnose/report > diagnose_report.json
curl -s http://localhost:8080/api/admin/system/info > system_info.json
指标监控
curl -s http://localhost:8080/actuator/prometheus
curl -s http://localhost:8080/actuator/metrics/openclaw.task.completed
curl -s http://localhost:8080/actuator/metrics/openclaw.task.failed
curl -s http://localhost:8080/actuator/metrics/openclaw.worker.active
常见问题速查
| 问题现象 | 可能原因 | 排查命令 | 解决方案 |
|---|
| 服务无法启动 | 端口占用/配置错误 | netstat -tlnp, 查看启动日志 | 检查端口,修正配置 |
| 数据库连接失败 | 配置错误/网络问题 | mysql -h host -u user -p | 检查配置,网络 |
| Redis 连接失败 | 配置错误/服务未启动 | redis-cli ping | 检查配置,启动 Redis |
| Worker 注册失败 | 网络不通/配置错误 | telnet server 9090 | 检查网络,配置 |
| 任务执行失败 | 脚本错误/超时 | 查看任务日志 | 修复脚本,调整超时 |
| 任务堆积 | Worker 不足/阻塞 | 查看队列状态 | 扩容 Worker |
| 内存溢出 | 内存配置过小 | jstat -gc, jmap | 增加内存配置 |
| 响应慢 | 数据库慢查询/GC | 慢查询日志,GC 日志 | SQL 优化,JVM 调优 |
问题上报
收集诊断信息
#!/bin/bash
DIAG_DIR="/tmp/openclaw_diag_$(date +%Y%m%d_%H%M%S)"
mkdir -p $DIAG_DIR
uname -a > $DIAG_DIR/system_info.txt
free -h >> $DIAG_DIR/system_info.txt
df -h >> $DIAG_DIR/system_info.txt
curl -s http://localhost:8080/api/health > $DIAG_DIR/health.json
curl -s http://localhost:8080/api/cluster/info > $DIAG_DIR/cluster.json
tail -1000 /opt/openclaw/logs/openclaw-server.log > $DIAG_DIR/server.log
tail -1000 /opt/openclaw/logs/error.log > $DIAG_DIR/error.log
jstack $(pgrep -f openclaw-server) > $DIAG_DIR/thread_dump.txt 2>/dev/null
tar -czf $DIAG_DIR.tar.gz -C /tmp $(basename $DIAG_DIR)
echo "诊断信息已保存: $DIAG_DIR.tar.gz"