OpenClaw 是一个开源的系统监控工具,主要用于服务器性能监控和告警,以下是主要功能和使用方法:

核心功能
系统资源监控
- CPU 使用率、负载
- 内存使用情况(RAM、Swap)
- 磁盘空间和IO性能
- 网络流量和连接数
- 进程监控
服务监控
- HTTP/HTTPS 服务可用性
- 数据库服务状态
- 自定义端口检测
- 进程存活检查
告警功能
- 邮件通知
- Slack/钉钉/企业微信集成
- 自定义告警规则
- 阈值设置
基本使用
安装方式
-v /etc/openclaw:/config \ -v /var/run/docker.sock:/var/run/docker.sock \ openclaw/openclaw:latest # 或源码安装 git clone https://github.com/openclaw/openclaw.git cd openclaw pip install -r requirements.txt
配置文件示例
# config.yaml
monitoring:
interval: 60 # 监控间隔(秒)
metrics:
- name: cpu_usage
enabled: true
threshold: 80 # 告警阈值(%)
- name: memory_usage
enabled: true
threshold: 85
alerts:
email:
smtp_server: smtp.example.com
sender: alert@example.com
receivers:
- admin@example.com
启动服务
# 启动监控服务 openclaw start --config /path/to/config.yaml # 查看状态 openclaw status # 查看监控数据 openclaw metrics --format=json
监控脚本示例
自定义监控脚本
#!/usr/bin/env python3
# custom_monitor.py
import psutil
import requests
def check_disk_usage():
usage = psutil.disk_usage('/')
return {
'total': usage.total,
'used': usage.used,
'percent': usage.percent
}
def check_website(url):
try:
response = requests.get(url, timeout=10)
return {
'status_code': response.status_code,
'response_time': response.elapsed.total_seconds()
}
except Exception as e:
return {'error': str(e)}
Web界面操作
访问控制台
http://your-server:3000 # 默认端口
主要界面功能:
- 仪表盘 - 实时监控图表
- 主机列表 - 所有监控节点状态
- 告警中心 - 历史告警记录
- 配置管理 - 监控策略设置
告警配置
邮件告警配置
alerts:
rules:
- name: "高CPU使用率"
condition: "cpu_usage > 90"
duration: "5m" # 持续5分钟触发
actions:
- type: email
subject: "CPU告警"
- type: webhook
url: "https://your-webhook-url"
测试告警
# 手动触发测试 openclaw alert-test --rule="高CPU使用率"
最佳实践
-
监控策略:
- 生产环境:监控间隔30-60秒
- 测试环境:监控间隔1-5分钟
-
告警优化:
- 设置适当的阈值避免告警风暴
- 使用分级告警(警告/严重)
-
数据保留:
storage: retention_days: 30 # 数据保留30天 backup_enabled: true
故障排查
常见问题
# 查看日志 tail -f /var/log/openclaw.log # 检查配置 openclaw config-validate /path/to/config.yaml # 测试监控项 openclaw check-metric cpu_usage
监控代理状态
# 查看所有代理状态 openclaw agent list # 重启代理 openclaw agent restart <agent_id>
API接口(部分)
# 获取监控数据
GET /api/v1/metrics?metric=cpu_usage&hours=24
# 触发告警
POST /api/v1/alerts
{
"level": "critical",
"message": "服务异常",
"host": "server-01"
}
注意事项
- 生产环境建议使用TLS加密传输
- 定期备份配置文件和历史数据
- 根据实际负载调整监控频率
- 设置维护窗口避免误告警
具体使用细节请参考官方文档:https://docs.openclaw.org
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。