dsh-remote-vs 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +16 -6
- package/README.md +13 -5
- package/cordis.patch.yml +5 -0
- package/lib/client.js +1075 -9
- package/lib/index.js +381 -4
- package/lib/p2-router-fs.js +28 -0
- package/lib/types/client/MonitorView.d.ts +33 -0
- package/lib/types/client/api.d.ts +8 -0
- package/lib/types/client/metrics-model.d.ts +84 -0
- package/lib/types/client/store.d.ts +1 -1
- package/lib/types/metrics.d.ts +116 -0
- package/lib/types/monitor.d.ts +57 -0
- package/lib/types/p2/router-fs.d.ts +17 -1
- package/lib/types/protocol.d.ts +54 -0
- package/package.json +37 -37
- package/src/client/MonitorView.tsx +636 -0
- package/src/client/RemoteRoot.tsx +9 -2
- package/src/client/api.ts +16 -0
- package/src/client/i18n.ts +84 -0
- package/src/client/metrics-model.ts +242 -0
- package/src/client/store.tsx +2 -2
- package/src/client/vsc/vsc.css +464 -0
- package/src/metrics.ts +300 -0
- package/src/monitor.ts +203 -0
- package/src/p2/router-fs.ts +58 -0
- package/src/protocol.ts +58 -1
- package/src/routes.ts +47 -0
package/src/routes.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { migrateDshSsh, parseSshConfig, readDefaultSshConfig, type ParsedImport
|
|
|
24
24
|
import { TERMINAL_MAX_FRAME_BYTES, TerminalSessionRegistry } from './terminal.ts'
|
|
25
25
|
import { ForwardManager, validateForwardRequest } from './forward.ts'
|
|
26
26
|
import { LISTEN_PORTS_TIMEOUT_MS, listenPortsCommand, parseListenPorts } from './listen-ports.ts'
|
|
27
|
+
import { HostMonitor } from './monitor.ts'
|
|
27
28
|
import type { SessionChanges } from './changes/recorder.ts'
|
|
28
29
|
import { DEFAULT_TIMEOUTS, clampExecTimeout } from './timeouts.ts'
|
|
29
30
|
|
|
@@ -255,6 +256,10 @@ export function makeRoutes(deps: RemoteRoutesDeps): { routes: WebRoute[]; upgrad
|
|
|
255
256
|
const timeouts = (): RemoteTimeouts => deps.timeouts?.() ?? DEFAULT_TIMEOUTS
|
|
256
257
|
const files = new RemoteFiles(pool)
|
|
257
258
|
const terminalSessions = new TerminalSessionRegistry(pool)
|
|
259
|
+
// Cache/counters only (no timers, no listeners): a route rebuild losing it
|
|
260
|
+
// costs one extra sample, so it is safe to construct here instead of owning a
|
|
261
|
+
// fiber-scoped effect like the forward manager.
|
|
262
|
+
const monitor = new HostMonitor(pool)
|
|
258
263
|
const forwards = deps.forwards
|
|
259
264
|
|
|
260
265
|
/**
|
|
@@ -409,6 +414,7 @@ export function makeRoutes(deps: RemoteRoutesDeps): { routes: WebRoute[]; upgrad
|
|
|
409
414
|
// restarts. Close them BEFORE the connection they ride on goes away.
|
|
410
415
|
forwards?.stopAlias(alias)
|
|
411
416
|
pool.forget(alias)
|
|
417
|
+
monitor.forget(alias)
|
|
412
418
|
void worlds.dropHost(alias).catch(() => undefined)
|
|
413
419
|
if (!store.remove(alias)) {
|
|
414
420
|
writeJson(res, 404, { error: `unknown host alias: ${alias}` })
|
|
@@ -427,6 +433,7 @@ export function makeRoutes(deps: RemoteRoutesDeps): { routes: WebRoute[]; upgrad
|
|
|
427
433
|
}
|
|
428
434
|
try {
|
|
429
435
|
pool.forget(alias)
|
|
436
|
+
monitor.forget(alias)
|
|
430
437
|
void worlds.dropHost(alias).catch(() => undefined)
|
|
431
438
|
const entry = store.update(alias, body as Partial<HostPayload>)
|
|
432
439
|
writeJson(res, 200, { host: store.summarize(entry) })
|
|
@@ -1436,6 +1443,46 @@ export function makeRoutes(deps: RemoteRoutesDeps): { routes: WebRoute[]; upgrad
|
|
|
1436
1443
|
}
|
|
1437
1444
|
},
|
|
1438
1445
|
},
|
|
1446
|
+
// ------------------------------------------------------- host metrics
|
|
1447
|
+
// Live CPU/RAM/disk/net/temperature for the monitor panel. One bounded
|
|
1448
|
+
// POSIX probe per host (no helper, no Python on the remote); `HostMonitor`
|
|
1449
|
+
// caches a sample for a few seconds and diffs the CPU/net counters, so a
|
|
1450
|
+
// poll storm costs one channel and the first sample honestly says "unknown"
|
|
1451
|
+
// for the two deltas instead of inventing numbers.
|
|
1452
|
+
//
|
|
1453
|
+
// `alias` selects one host; omitting it samples every configured host (the
|
|
1454
|
+
// panel asks per host, so this is a convenience/tooling shape, not a
|
|
1455
|
+
// browser fan-out). Loopback-fenced like every other route.
|
|
1456
|
+
{
|
|
1457
|
+
kind: 'exact',
|
|
1458
|
+
path: REMOTE_API.metrics,
|
|
1459
|
+
handler: async (req, res) => {
|
|
1460
|
+
if (!isLoopbackRequest(req)) {
|
|
1461
|
+
writeJson(res, 403, { error: 'forbidden: loopback-only' })
|
|
1462
|
+
return
|
|
1463
|
+
}
|
|
1464
|
+
if (req.method !== 'GET') {
|
|
1465
|
+
writeJson(res, 405, { error: `method not allowed: ${req.method}` })
|
|
1466
|
+
return
|
|
1467
|
+
}
|
|
1468
|
+
const url = new URL(req.url ?? '/', 'http://localhost')
|
|
1469
|
+
const alias = queryParam(url, 'alias')
|
|
1470
|
+
const refresh = queryParam(url, 'refresh') === '1'
|
|
1471
|
+
if (alias !== undefined && alias !== '' && store.get(alias) === undefined) {
|
|
1472
|
+
writeJson(res, 404, { error: `unknown host alias: ${alias}` })
|
|
1473
|
+
return
|
|
1474
|
+
}
|
|
1475
|
+
const aliases = alias === undefined || alias === ''
|
|
1476
|
+
? store.list().map(host => host.alias)
|
|
1477
|
+
: [alias]
|
|
1478
|
+
try {
|
|
1479
|
+
const hosts = await Promise.all(aliases.map(host => monitor.sample(host, refresh)))
|
|
1480
|
+
writeJson(res, 200, { hosts })
|
|
1481
|
+
} catch (error) {
|
|
1482
|
+
writeJson(res, 502, { error: error instanceof Error ? error.message : String(error) })
|
|
1483
|
+
}
|
|
1484
|
+
},
|
|
1485
|
+
},
|
|
1439
1486
|
]
|
|
1440
1487
|
|
|
1441
1488
|
// ---------------------------------------------- terminal (upgrade)
|