feat(host): /api/host CPU/mem/disk/net from /proc

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-02 22:34:04 +10:00
parent 03803f39f0
commit 3492b24dac
4 changed files with 71 additions and 0 deletions

22
tests/api/host.test.js Normal file
View File

@@ -0,0 +1,22 @@
import { describe, it, expect, beforeAll } from 'vitest';
import request from 'supertest';
import { setup } from './helpers.js';
let app, ownerHeaders;
beforeAll(async () => { ({ app, ownerHeaders } = await setup()); });
describe('host api', () => {
it('401 without auth', async () => {
expect((await request(app).get('/api/host')).status).toBe(401);
});
it('returns cpu/mem/disk/net shape', async () => {
const res = await request(app).get('/api/host').set(ownerHeaders);
expect(res.status).toBe(200);
expect(res.body.cpu_pct).toBeGreaterThanOrEqual(0);
expect(res.body.cpu_pct).toBeLessThanOrEqual(100);
expect(res.body.mem.total).toBeGreaterThan(0);
expect(res.body.mem.used).toBeGreaterThanOrEqual(0);
expect(res.body.disk).toHaveProperty('pct');
expect(res.body.net).toHaveProperty('rx_bytes');
});
});