接口总览
所有接口挂在 /api 前缀下,返回 JSON。除 /api/health 和登录相关接口外,其余接口都需要携带登录后的 Cookie,否则返回:
json
{ "error": "UNAUTHORIZED" }通用约定
- 容量字段单位为字节
- 占用率字段(
cpuLoad、memUsage、diskUsage)与进程cpu/mem为 0~100 的百分比 uptime单位为秒- 错误统一返回
{ "error": "错误码" },不返回 HTML
鉴权
GET /api/auth/status
公开。用于判断是否已初始化、当前请求是否已登录。
json
{
"initialized": true,
"authenticated": false,
"user": null
}| 字段 | 类型 | 说明 |
|---|---|---|
initialized | boolean | 数据库中是否已有管理员 |
authenticated | boolean | 当前 Cookie 是否对应有效会话 |
user | object | null | 已登录时为 { id, username } |
POST /api/auth/login
公开。请求体:
json
{ "username": "admin", "password": "你的密码" }成功时返回用户并写入 Cookie:
json
{ "user": { "id": 1, "username": "admin" } }| 状态码 | error | 触发条件 |
|---|---|---|
| 400 | BAD_REQUEST | 用户名或密码不是字符串 |
| 401 | INVALID_CREDENTIALS | 账号不存在或密码错误 |
| 429 | TOO_MANY_ATTEMPTS | 同 IP 连续失败 5 次,锁定 15 分钟 |
Cookie 名为 sid,属性:httpOnly、sameSite=lax、path=/、有效期 SESSION_DAYS(默认 7 天)。
POST /api/auth/logout
公开。删除当前会话并清除 Cookie,返回 204,无响应体。
健康检查
GET /api/health
公开。
json
{ "status": "ok" }系统信息
以下接口均需要有效 Cookie。
GET /api/system/cpu
json
{
"cpuBrand": "Gen Intel® Core™ i7-13650HX",
"cpuCores": 20,
"cpuLoad": 40.97
}| 字段 | 类型 | 说明 |
|---|---|---|
cpuBrand | string | CPU 型号 |
cpuCores | number | 核心数 |
cpuLoad | number | 当前总体负载百分比 |
GET /api/system/memory
json
{
"memTotal": 25551560704,
"memUsed": 14906839040,
"memUsage": 58.34
}| 字段 | 类型 | 说明 |
|---|---|---|
memTotal | number | 总内存(字节) |
memUsed | number | 已用内存(字节) |
memUsage | number | memUsed / memTotal 的百分比 |
GET /api/system/disk
json
{
"diskTotal": 509720125440,
"diskUsed": 391022161920,
"diskUsage": 76.71
}| 字段 | 类型 | 说明 |
|---|---|---|
diskTotal | number | 所有卷总容量(字节) |
diskUsed | number | 所有卷已用容量(字节) |
diskUsage | number | 按 diskUsed / diskTotal 计算,不是各卷百分比的平均 |
GET /api/system/network
json
{
"rxBytes": 109951162777,
"txBytes": 43980465111
}| 字段 | 类型 | 说明 |
|---|---|---|
rxBytes | number | 所有网卡自开机以来的累计接收字节数 |
txBytes | number | 所有网卡自开机以来的累计发送字节数 |
注意:这是累计值(rx_bytes / tx_bytes),不是实时速率。
GET /api/system/processes
返回 si.processes() 的全部进程,未排序、未截断,前端只取前 10 条展示。
json
[
{ "pid": 10856, "cpu": 2.59, "mem": 0.56 },
{ "pid": 32744, "cpu": 1.75, "mem": 3.5 }
]| 字段 | 类型 | 说明 |
|---|---|---|
pid | number | 进程 ID |
cpu | number | CPU 占用百分比 |
mem | number | 内存占用百分比(不是字节) |
该接口会枚举全部进程,开销明显大于其它接口。
GET /api/system/os
json
{
"hostname": "Cnkrru",
"type": "Windows_NT",
"release": "10.0.26100",
"arch": "x64",
"uptime": 16565.04
}| 字段 | 类型 | 说明 |
|---|---|---|
hostname | string | 主机名 |
type | string | 系统类型 |
release | string | 系统版本号 |
arch | string | 架构 |
uptime | number | 已运行时长(秒) |
尚未提供
- 文件管理、操作历史、日志、系统设置相关接口