http://localhost:8080application/json{ "code": 0, "message": "ok", "data": {} }GET /api/health
响应示例:
{
"code": 0,
"message": "ok"
}
GET /api/mqtt
响应示例:
{
"code": 0,
"message": "ok",
"data": [
{
"id": 1,
"broker": "tcp://127.0.0.1:1883",
"client_id": "opencode-monitor",
"topic": "opencode/status",
"enabled": true
}
]
}
POST /api/mqtt
请求体:
{
"broker": "tcp://127.0.0.1:1883",
"client_id": "opencode-monitor",
"topic": "opencode/status",
"enabled": true
}
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| broker | string | 是 | - | MQTT Broker 地址 |
| client_id | string | 否 | opencode-monitor | 客户端 ID |
| topic | string | 否 | opencode/status | 主题前缀 |
| enabled | boolean | 否 | true | 是否启用 |
响应示例:
{
"code": 0,
"message": "创建成功",
"data": {
"id": 1,
"broker": "tcp://127.0.0.1:1883",
"client_id": "opencode-monitor",
"topic": "opencode/status",
"enabled": true
}
}
GET /api/mqtt/:id
路径参数: | 参数 | 类型 | 说明 | |------|------|------| | id | integer | 配置 ID |
响应示例:
{
"code": 0,
"message": "ok",
"data": {
"id": 1,
"broker": "tcp://127.0.0.1:1883",
"client_id": "opencode-monitor",
"topic": "opencode/status",
"enabled": true
}
}
PUT /api/mqtt/:id
路径参数: | 参数 | 类型 | 说明 | |------|------|------| | id | integer | 配置 ID |
请求体:
{
"broker": "tcp://192.168.1.100:1883",
"client_id": "my-monitor",
"topic": "my/topic",
"enabled": false
}
响应示例:
{
"code": 0,
"message": "更新成功",
"data": {
"id": 1,
"broker": "tcp://192.168.1.100:1883",
"client_id": "my-monitor",
"topic": "my/topic",
"enabled": false
}
}
DELETE /api/mqtt/:id
路径参数: | 参数 | 类型 | 说明 | |------|------|------| | id | integer | 配置 ID |
响应示例:
{
"code": 0,
"message": "删除成功"
}
所有错误响应格式:
{
"code": -1,
"message": "错误信息"
}
# 方式1: 独立启动 API 服务
./bin/opencode-monitor serve --addr :8080
# 方式2: 监控时同时启动 API 服务
./bin/opencode-monitor monitor --ports 4096 --api-addr :8080
API 已启用 CORS,支持跨域请求。