fix(monitoring,db,proxy): cap/dedupe shared-host disk mounts, index metrics_disks, defer startup maintenance & bind split proxy port
This commit is contained in:
parent
65d88f0a1e
commit
5933727a01
8 changed files with 292 additions and 19 deletions
|
|
@ -6,6 +6,11 @@ import { afterEach, describe, expect, it } from 'vitest';
|
|||
import { ConfigManager } from '../src/server/config/config-manager.js';
|
||||
import { openDatabase } from '../src/server/db/database.js';
|
||||
import {
|
||||
migration005MetricsDisksIndexes,
|
||||
RUNAWAY_METRICS_DISKS_THRESHOLD,
|
||||
} from '../src/server/db/migrations/005_metrics_disks_indexes.js';
|
||||
import {
|
||||
MAX_AUTO_DISCOVERED_MOUNTS,
|
||||
parseBsdOutput,
|
||||
parseLinuxOutput,
|
||||
parseMacOsOutput,
|
||||
|
|
@ -253,4 +258,105 @@ describe('OS Collectors, ServerInspector, Health Probes & MonitoringService', ()
|
|||
expect(history7d.granularity).toBe('1h');
|
||||
expect(history7d.points.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('deduplicates bind mounts, filters shared-host/container noise, caps auto-discovered mounts, and honors explicit filters', () => {
|
||||
const bindLines = Array.from(
|
||||
{ length: 30 },
|
||||
(_, i) => `/dev/sda1 ext4 104857600 41943040 62914560 40% /home/virtfs/user${i + 1}/usr`,
|
||||
);
|
||||
const nvmeLines = Array.from(
|
||||
{ length: 35 },
|
||||
(_, i) => `/dev/nvme0n1p${i + 1} ext4 ${10485760 + i * 1024} 5242880 5242880 50% /srv/vol${i + 1}`,
|
||||
);
|
||||
|
||||
const sharedHostOut = [
|
||||
'===STAT===',
|
||||
'cpu 1000 0 200 8800 0 0 0 0 0 0',
|
||||
'===MEM===',
|
||||
'MemTotal: 8192000 kB',
|
||||
'MemAvailable: 4096000 kB',
|
||||
'===LOAD===',
|
||||
'0.50 0.40 0.30 1/120 55',
|
||||
'===UPTIME===',
|
||||
'12000.00 24000.00',
|
||||
'===NET===',
|
||||
' eth0: 1000 10 0 0 0 0 0 0 2000 10',
|
||||
'===DF===',
|
||||
'Filesystem Type 1024-blocks Used Available Capacity Mounted on',
|
||||
...bindLines,
|
||||
'/dev/sda1 ext4 104857600 41943040 62914560 40% /',
|
||||
'/dev/loop0 ext4 102400 102400 0 100% /snap/core/1',
|
||||
'/dev/sdb1 ext4 104857600 41943040 62914560 40% /var/lib/docker/overlay2/abc/merged',
|
||||
'/dev/sdc1 ext4 104857600 41943040 62914560 40% /var/cagefs/u1',
|
||||
'lxcfs fuse.lxcfs 1024 0 1024 0% /proc/cpuinfo',
|
||||
...nvmeLines,
|
||||
].join('\n');
|
||||
|
||||
const autoParsed = parseLinuxOutput(sharedHostOut, undefined, undefined, 20_000);
|
||||
expect(autoParsed.disks.length).toBe(MAX_AUTO_DISCOVERED_MOUNTS);
|
||||
const mounts = autoParsed.disks.map((d) => d.mountPoint);
|
||||
expect(mounts[0]).toBe('/');
|
||||
expect(mounts.some((m) => m.startsWith('/home/virtfs'))).toBe(false);
|
||||
expect(mounts.some((m) => m.startsWith('/snap'))).toBe(false);
|
||||
expect(mounts.some((m) => m.startsWith('/var/lib/docker'))).toBe(false);
|
||||
expect(mounts.some((m) => m.startsWith('/var/cagefs'))).toBe(false);
|
||||
expect(mounts.some((m) => m.startsWith('/proc'))).toBe(false);
|
||||
|
||||
// Explicit filter overrides noisy-path suppression when user selects a specific mount
|
||||
const filtered = parseLinuxOutput(sharedHostOut, undefined, ['/home/virtfs/user5/usr'], 20_000);
|
||||
expect(filtered.disks.map((d) => d.mountPoint)).toEqual(['/home/virtfs/user5/usr']);
|
||||
});
|
||||
|
||||
it('creates metric indexes in migration 005 and truncates runaway metrics_disks rows above threshold', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gcoord-mig005-test-'));
|
||||
const db = openDatabase(path.join(dir, 'gcoord.db'));
|
||||
cleanups.push(() => {
|
||||
db.close();
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const indexes = (
|
||||
db
|
||||
.prepare("SELECT name FROM sqlite_master WHERE type = 'index'")
|
||||
.all() as Array<{ name: string }>
|
||||
).map((r) => r.name);
|
||||
expect(indexes).toContain('idx_metrics_disks_server_ts');
|
||||
expect(indexes).toContain('idx_metrics_disks_ts');
|
||||
expect(indexes).toContain('idx_metrics_raw_ts');
|
||||
expect(indexes).toContain('idx_probe_results_ts');
|
||||
|
||||
// Below threshold: preserves existing metrics_disks rows
|
||||
db.prepare(
|
||||
'INSERT INTO metrics_raw (ts, server_id, cpu_pct, mem_used_mb, mem_total_mb, net_rx_bps, net_tx_bps, load_1m, uptime_sec) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
).run(1000, 's1', 10, 100, 1000, 0, 0, 0.1, 60);
|
||||
const insDisk = db.prepare(
|
||||
'INSERT INTO metrics_disks (ts, server_id, mount_point, fs_type, used_mb, total_mb, used_pct) VALUES (?, ?, ?, ?, ?, ?, ?)',
|
||||
);
|
||||
for (let i = 0; i < 5; i++) {
|
||||
insDisk.run(1000, 's1', `/m${i}`, 'ext4', 10, 100, 10);
|
||||
}
|
||||
migration005MetricsDisksIndexes.up(db);
|
||||
expect(
|
||||
(db.prepare('SELECT COUNT(*) AS n FROM metrics_disks').get() as { n: number }).n,
|
||||
).toBe(5);
|
||||
|
||||
// Above threshold: truncates runaway metrics_disks while preserving metrics_raw
|
||||
db.transaction(() => {
|
||||
const target = RUNAWAY_METRICS_DISKS_THRESHOLD + 1;
|
||||
for (let i = 5; i < target; i++) {
|
||||
insDisk.run(2000 + Math.floor(i / 500), 's1', `/m${i}`, 'ext4', 10, 100, 10);
|
||||
}
|
||||
})();
|
||||
expect(
|
||||
(db.prepare('SELECT COUNT(*) AS n FROM metrics_disks').get() as { n: number }).n,
|
||||
).toBe(RUNAWAY_METRICS_DISKS_THRESHOLD + 1);
|
||||
|
||||
migration005MetricsDisksIndexes.up(db);
|
||||
expect(
|
||||
(db.prepare('SELECT COUNT(*) AS n FROM metrics_disks').get() as { n: number }).n,
|
||||
).toBe(0);
|
||||
expect(
|
||||
(db.prepare('SELECT COUNT(*) AS n FROM metrics_raw').get() as { n: number }).n,
|
||||
).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue