4.7 KiB
4.7 KiB
内部 API 参考
除登录、健康检查外,API 都要求有效登录会话。
修改数据的请求需要 CSRF:
X-CSRF-Token: <token>
Token 存在于页面:
<meta name="csrf-token" content="...">
健康检查
GET /healthz
无需登录。
{"ok":true,"service":"nexus-system-dashboard"}
系统数据
GET /api/system
返回当前 CPU、内存、磁盘容量、磁盘 I/O、网络接口、温度和进程快照。
关键磁盘字段:
{
"disk": {
"percent": 68.5,
"utilization": 21.3,
"read_rate": 10485760,
"write_rate": 5242880,
"devices": [
{
"name": "sda",
"utilization": 21.3,
"read_rate": 10485760,
"write_rate": 5242880,
"read_iops": 12.2,
"write_iops": 4.8
}
]
}
}
GET /api/system/history?hours=72
固定窗口允许 0.5 到 72 小时。
{
"ok": true,
"sample_seconds": 30,
"generated_at": "2026-11-11T02:00:00+00:00",
"data": [
{
"t": "2026-11-11T02:00:00+00:00",
"cpu": 20.5,
"memory": 45.2,
"recv": 1024,
"sent": 512,
"disk": 18.4,
"disk_read": 2048,
"disk_write": 1024,
"disk_devices": [],
"network_interfaces": [
{
"name": "eth0",
"recv_rate": 1024,
"sent_rate": 512
}
]
}
]
}
升级前没有磁盘 I/O 数据的旧系统样本,disk 可能为 null。
数据源
GET /api/sources
POST /api/sources
PUT /api/sources/{id}
DELETE /api/sources/{id}
GET /api/categories
POST /api/categories
PUT /api/categories/{id}
DELETE /api/categories/{id}
## 界面配置
```http
GET /api/preferences
PUT /api/preferences
保存单个配置:
{
"key": "nexus.dashboard.layout.v2",
"value": {
"autoAlign": true,
"categories": [
{"id": "default", "name": "默认分类"},
{"id": "network", "name": "网络与存储"}
],
"groups": {
"panels": {
"items": {
"storage": {
"categoryIds": ["default", "network"],
"title": "存储容量",
"layouts": {
"__all__": {
"gridId": "panels", "w": 5, "h": 4, "order": 0
},
"default": {
"gridId": "panels", "w": 3, "h": 2, "order": 0
},
"network": {
"gridId": "metrics", "w": 8, "h": 5, "order": 0
}
}
}
}
}
}
}
}
配置按登录用户保存在服务端。/api/categories 仅管理数据源设置页使用的分组,不决定大屏板块分类。
数据源对象:
```json
{
"name": "系统资源",
"category": "系统资源",
"provider": "system",
"url": "system://local",
"headers": {},
"interval_seconds": 60,
"enabled": true,
"fields": []
}
provider 可选:
jsonnextcloudcommandsystem
数据源整体开关
POST /api/sources/{id}/enabled
PUT /api/sources/{id}/enabled
{"enabled": false}
关闭后停止采样、禁止手动刷新、从大屏隐藏,并保留配置和历史。
数据源测试和发现
POST /api/sources/test
POST /api/sources/discover
发现接口会遍历响应中的数值叶子,返回字段路径。生成字段名称限制在 60 个字符以内。
自定义指标
GET /api/monitors?hours=72
返回启用数据源中启用字段的最新值和历史。停用数据源不会出现在结果中。
字段主要属性:
{
"name": "存储使用率",
"path": "",
"expression": "used / total * 100",
"variables_json": "{\"used\":\"storage.used\",\"total\":\"storage.total\"}",
"enabled": true,
"display_type": "chart",
"placement": "overview",
"chart_group": "存储状态",
"alert_enabled": true,
"alert_operator": ">=",
"alert_threshold": 90,
"alert_command": "/opt/scripts/storage-alert.sh",
"alert_cooldown_seconds": 300
}
手动刷新
POST /api/sources/{id}/refresh
数据源整体关闭时返回 409。
修改密码
POST /api/account/password
{
"current_password": "old-password",
"new_password": "new-password",
"confirmation": "new-password"
}
错误格式
{"ok": false, "error": "错误说明"}
常见状态码:
| 状态 | 含义 |
|---|---|
| 400 | 配置或请求格式错误 |
| 401 | 登录状态无效 |
| 404 | 数据源或接口不存在 |
| 409 | 数据源已关闭 |
| 413 | 请求内容过大 |
| 429 | 登录或上游接口限流 |
| 500 | 服务端处理异常 |
| 502 | 外部接口或命令失败 |