dsh-nvtop-panel 1.1.2 → 1.2.1
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.md +48 -6
- package/client.js +118 -29
- package/index.js +410 -51
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -32,9 +32,12 @@ PID USER DEV TYPE GPU GPU MEM CPU HOST MEM Command
|
|
|
32
32
|
HOST MEM · Command`. GPU memory comes from `nvidia-smi --query-compute-apps`; user,
|
|
33
33
|
CPU %, host RSS, and full command line come from one batched `ps` call; each process
|
|
34
34
|
is mapped to its device via GPU UUID.
|
|
35
|
-
- `TYPE` is `C` (compute)
|
|
36
|
-
- `GPU` is
|
|
37
|
-
|
|
35
|
+
- `TYPE` is `C` (compute) or `G` (graphics), as reported by `nvidia-smi pmon`.
|
|
36
|
+
- `GPU` is **this process's own SM (compute) utilisation** on its device, read
|
|
37
|
+
from `nvidia-smi pmon`, matched by device *and* pid — never the whole-GPU
|
|
38
|
+
figure. A process with no SM activity in the sample window shows `0%`.
|
|
39
|
+
On a driver that does not report per-process figures the column shows `—`
|
|
40
|
+
rather than substituting a misleading number.
|
|
38
41
|
- **Auto-refresh**, interval configurable per profile (default 2 s), server samples
|
|
39
42
|
cached 1 s so overlapping polls share one `nvidia-smi` run.
|
|
40
43
|
- **Theme-native UI**: all styling uses DSH theme tokens (`--dsw-alias-*`), light/dark
|
|
@@ -74,11 +77,50 @@ Tunable in your profile's `cordis.patch.yml`:
|
|
|
74
77
|
```yaml
|
|
75
78
|
- id: dsh-nvtop-panel
|
|
76
79
|
config:
|
|
77
|
-
intervalMs: 2000 # client poll interval, 500
|
|
80
|
+
intervalMs: 2000 # client poll interval, 500-60000 ms
|
|
81
|
+
peers: # extra units sampled over SSH (see DGX Spark below)
|
|
82
|
+
- host: 192.0.2.11
|
|
83
|
+
title: 'Spark #2'
|
|
84
|
+
- host: 192.0.2.21
|
|
85
|
+
user: sparky
|
|
86
|
+
port: 22
|
|
78
87
|
```
|
|
79
88
|
|
|
80
|
-
Editing the interval restarts the plugin and the panel picks
|
|
81
|
-
next poll.
|
|
89
|
+
Editing the interval or the peer list restarts the plugin and the panel picks
|
|
90
|
+
up the new value on the next poll.
|
|
91
|
+
|
|
92
|
+
## DGX Spark (GB10) support
|
|
93
|
+
|
|
94
|
+
**Unified memory.** On a DGX Spark the GB10 GPU shares one LPDDR5X pool with
|
|
95
|
+
the CPU, and `nvidia-smi` reports `memory.used` / `memory.total` as `[N/A]`.
|
|
96
|
+
Following the [sparkDash](https://github.com/MiaAI-Lab/sparkDash) approach, the
|
|
97
|
+
card then shows:
|
|
98
|
+
|
|
99
|
+
- **Memory (unified pool)** - `used` is the GPU-allocated share (sum of
|
|
100
|
+
compute-apps), `total` is the OS-visible pool (`MemTotal`);
|
|
101
|
+
- **Pool** - a second bar with whole-pool occupancy (GPU + CPU), with
|
|
102
|
+
`MemAvailable` as the free figure;
|
|
103
|
+
- a `unified` chip marks such cards. Discrete GPUs keep using `nvidia-smi`
|
|
104
|
+
values unchanged.
|
|
105
|
+
|
|
106
|
+
**Daisy-chained units.** Spark clusters do not expose peer GPUs through local
|
|
107
|
+
`nvidia-smi`; each unit is its own machine. Add peers with the `peers` config
|
|
108
|
+
above and the plugin samples each one over SSH (BatchMode, key auth only -
|
|
109
|
+
`ssh <host>` must work without a password for the user dsh runs as).
|
|
110
|
+
Interconnect peers usually sit on `192.0.2.x` (the ConnectX subnet): check
|
|
111
|
+
`ip neigh`. Cards from every unit share one grid (side by side when width
|
|
112
|
+
allows) and one merged nvtop-style process table whose `DEV` column is the unit
|
|
113
|
+
index (`Spark #N` labels the cards). Peers are probed in the background, so a
|
|
114
|
+
down or slow peer never delays the panel: it keeps showing its last error
|
|
115
|
+
(`No route to host`, `Permission denied`, …) as a banner and retries every 10 s.
|
|
116
|
+
A peer without an NVIDIA GPU shows a note instead of silently disappearing.
|
|
117
|
+
|
|
118
|
+
Anyone who can open this DSH page can read the peer units' process tables;
|
|
119
|
+
peers are therefore exactly as visible as the dsh user's SSH keys allow.
|
|
120
|
+
|
|
121
|
+
Per-process SM utilisation comes from `nvidia-smi pmon`. Per-process unified-memory
|
|
122
|
+
splits remain a driver-level statistic that `nvidia-smi` does not expose: `GPU MEM` is
|
|
123
|
+
the compute-app allocation, as nvtop does on this hardware.
|
|
82
124
|
|
|
83
125
|
## Verify
|
|
84
126
|
|
package/client.js
CHANGED
|
@@ -14,6 +14,8 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
panel: 'GPU monitor',
|
|
15
15
|
gpus: '{n} GPU',
|
|
16
16
|
gpusOther: '{n} GPUs',
|
|
17
|
+
units: '{n} unit',
|
|
18
|
+
unitsOther: '{n} units',
|
|
17
19
|
utilization: 'Utilization',
|
|
18
20
|
memory: 'Memory',
|
|
19
21
|
temperature: 'Temp',
|
|
@@ -23,6 +25,7 @@ window.__ModuleLoader__.load({
|
|
|
23
25
|
noProcesses: 'No GPU processes',
|
|
24
26
|
unavailable: 'GPU stats unavailable',
|
|
25
27
|
stale: 'Waiting for data…',
|
|
28
|
+
localUnit: 'This machine',
|
|
26
29
|
pid: 'PID',
|
|
27
30
|
user: 'USER',
|
|
28
31
|
dev: 'DEV',
|
|
@@ -32,6 +35,8 @@ window.__ModuleLoader__.load({
|
|
|
32
35
|
cpu: 'CPU',
|
|
33
36
|
hostMem: 'HOST MEM',
|
|
34
37
|
command: 'Command',
|
|
38
|
+
gpuTitle: 'This process\'s own SM (compute) utilisation on its GPU, not the whole-GPU figure',
|
|
39
|
+
gpuMemTitle: 'GPU memory allocated to this process',
|
|
35
40
|
},
|
|
36
41
|
};
|
|
37
42
|
|
|
@@ -60,6 +65,16 @@ window.__ModuleLoader__.load({
|
|
|
60
65
|
return value === null || value === undefined ? '—' : `${Math.round(value)}%`;
|
|
61
66
|
}
|
|
62
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Per-process SM utilisation. pmon prints "-" for a context that used no SM
|
|
70
|
+
* time in the sample window, which reads as 0 % only when the driver does
|
|
71
|
+
* report per-process figures; otherwise the figure is simply unavailable.
|
|
72
|
+
*/
|
|
73
|
+
function fmtProcGpu(p, utilReported) {
|
|
74
|
+
if (p.gpuUtilization !== null && p.gpuUtilization !== undefined) return `${Math.round(p.gpuUtilization)}%`;
|
|
75
|
+
return utilReported ? '0%' : '—';
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
function levelClass(ratio) {
|
|
64
79
|
if (ratio === null || ratio === undefined) return 'nvtp-empty';
|
|
65
80
|
if (ratio >= 0.9) return 'nvtp-hot';
|
|
@@ -70,8 +85,13 @@ window.__ModuleLoader__.load({
|
|
|
70
85
|
function Bar(props) {
|
|
71
86
|
const ratio = props.ratio;
|
|
72
87
|
const pct = ratio === null || ratio === undefined ? 0 : Math.max(0, Math.min(100, ratio * 100));
|
|
88
|
+
const otherPct = props.other === null || props.other === undefined
|
|
89
|
+
? 0 : Math.max(0, Math.min(100 - pct, props.other * 100));
|
|
73
90
|
return h('div', { className: 'nvtp-bar ' + levelClass(ratio) },
|
|
74
|
-
h('div', { className: 'nvtp-bar-fill', style: { width: pct + '%' } })
|
|
91
|
+
h('div', { className: 'nvtp-bar-fill', style: { width: pct + '%' } }),
|
|
92
|
+
props.other === null || props.other === undefined
|
|
93
|
+
? null
|
|
94
|
+
: h('div', { className: 'nvtp-bar-fill nvtp-bar-other', style: { width: otherPct + '%' } }));
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
function Stat(props) {
|
|
@@ -81,23 +101,39 @@ window.__ModuleLoader__.load({
|
|
|
81
101
|
}
|
|
82
102
|
|
|
83
103
|
function GpuCard(props) {
|
|
84
|
-
const { gpu, t } = props;
|
|
104
|
+
const { gpu, t, unitTitle } = props;
|
|
85
105
|
const memRatio = gpu.memoryUsed !== null && gpu.memoryTotal
|
|
86
106
|
? gpu.memoryUsed / gpu.memoryTotal : null;
|
|
87
107
|
const powerRatio = gpu.powerDraw !== null && gpu.powerLimit
|
|
88
108
|
? gpu.powerDraw / gpu.powerLimit : null;
|
|
109
|
+
// Unified pool: stacked bar — GPU-allocated share plus everything else
|
|
110
|
+
// (CPU, page cache) that eats the shared pool; free stays empty.
|
|
111
|
+
const unifiedPool = gpu.unified === true && gpu.memoryAvailable !== null && gpu.memoryTotal;
|
|
112
|
+
const otherRatio = unifiedPool
|
|
113
|
+
? Math.max(0, (gpu.memoryTotal - gpu.memoryAvailable) / gpu.memoryTotal
|
|
114
|
+
- (memRatio ?? 0))
|
|
115
|
+
: null;
|
|
116
|
+
const memTitle = unifiedPool
|
|
117
|
+
? `GPU ${fmtMemory(gpu.memoryUsed)} · other ${fmtMemory(Math.max(0, gpu.memoryTotal - gpu.memoryAvailable - gpu.memoryUsed))} · free ${fmtMemory(gpu.memoryAvailable)} of ${fmtMemory(gpu.memoryTotal)} unified pool`
|
|
118
|
+
: undefined;
|
|
89
119
|
return h('section', { className: 'nvtp-card' },
|
|
90
120
|
h('header', { className: 'nvtp-card-head' },
|
|
91
121
|
h('span', { className: 'nvtp-card-name' }, gpu.name),
|
|
92
|
-
|
|
122
|
+
gpu.unified === true
|
|
123
|
+
? h('span', { className: 'nvtp-chip' }, 'unified')
|
|
124
|
+
: null,
|
|
125
|
+
h('span', { className: 'nvtp-card-index' },
|
|
126
|
+
unitTitle !== null && unitTitle !== undefined
|
|
127
|
+
? `${unitTitle} · GPU ${gpu.index}`
|
|
128
|
+
: `GPU ${gpu.index}`)),
|
|
93
129
|
h('div', { className: 'nvtp-rows' },
|
|
94
130
|
h('div', { className: 'nvtp-row' },
|
|
95
131
|
h('span', { className: 'nvtp-row-label' }, t('utilization')),
|
|
96
132
|
h(Bar, { ratio: gpu.utilization === null ? null : gpu.utilization / 100 }),
|
|
97
133
|
h('span', { className: 'nvtp-row-value' }, fmtPercent(gpu.utilization))),
|
|
98
|
-
h('div', { className: 'nvtp-row' },
|
|
134
|
+
h('div', { className: 'nvtp-row', title: memTitle },
|
|
99
135
|
h('span', { className: 'nvtp-row-label' }, t('memory')),
|
|
100
|
-
h(Bar, { ratio: memRatio }),
|
|
136
|
+
h(Bar, { ratio: memRatio, other: otherRatio }),
|
|
101
137
|
h('span', { className: 'nvtp-row-value' },
|
|
102
138
|
`${fmtMemory(gpu.memoryUsed)} / ${fmtMemory(gpu.memoryTotal)}`)),
|
|
103
139
|
h('div', { className: 'nvtp-row' },
|
|
@@ -112,30 +148,34 @@ window.__ModuleLoader__.load({
|
|
|
112
148
|
}
|
|
113
149
|
|
|
114
150
|
function ProcessTable(props) {
|
|
115
|
-
const { processes, t } = props;
|
|
151
|
+
const { processes, t, multiUnit } = props;
|
|
116
152
|
if (processes.length === 0) {
|
|
117
153
|
return h('div', { className: 'nvtp-empty-note' }, t('noProcesses'));
|
|
118
154
|
}
|
|
155
|
+
const deviceText = (p) => {
|
|
156
|
+
const gpuIndex = p.device === null || p.device === undefined ? '—' : String(p.device);
|
|
157
|
+
return multiUnit ? String(p.unitIdx) : gpuIndex;
|
|
158
|
+
};
|
|
119
159
|
return h('div', { className: 'nvtp-scroll' },
|
|
120
160
|
h('table', { className: 'nvtp-table nvtp-procs-table' },
|
|
121
161
|
h('thead', null,
|
|
122
162
|
h('tr', null,
|
|
123
163
|
h('th', { className: 'nvtp-num' }, t('pid')),
|
|
124
164
|
h('th', null, t('user')),
|
|
125
|
-
h('th', { className: 'nvtp-num' }, t('dev')),
|
|
165
|
+
h('th', { className: 'nvtp-num', title: multiUnit ? 'unit index' : undefined }, t('dev')),
|
|
126
166
|
h('th', null, t('type')),
|
|
127
|
-
h('th', { className: 'nvtp-num' }, t('gpu')),
|
|
128
|
-
h('th', { className: 'nvtp-num' }, t('gpuMem')),
|
|
167
|
+
h('th', { className: 'nvtp-num', title: t('gpuTitle') }, t('gpu')),
|
|
168
|
+
h('th', { className: 'nvtp-num', title: t('gpuMemTitle') }, t('gpuMem')),
|
|
129
169
|
h('th', { className: 'nvtp-num' }, t('cpu')),
|
|
130
170
|
h('th', { className: 'nvtp-num' }, t('hostMem')),
|
|
131
171
|
h('th', { className: 'nvtp-cmd' }, t('command')))),
|
|
132
172
|
h('tbody', null,
|
|
133
|
-
processes.map((p) => h('tr', { key: p.pid + ':' + (p.device ?? '') + ':' + p.command.slice(0, 24) },
|
|
173
|
+
processes.map((p) => h('tr', { key: p.unitIdx + ':' + p.pid + ':' + (p.device ?? '') + ':' + p.command.slice(0, 24) },
|
|
134
174
|
h('td', { className: 'nvtp-num' }, fmtInt(p.pid)),
|
|
135
175
|
h('td', { className: 'nvtp-user' }, p.user ?? '—'),
|
|
136
|
-
h('td', { className: 'nvtp-num' },
|
|
176
|
+
h('td', { className: 'nvtp-num' }, deviceText(p)),
|
|
137
177
|
h('td', { className: 'nvtp-type' }, p.type ?? '—'),
|
|
138
|
-
h('td', { className: 'nvtp-num' },
|
|
178
|
+
h('td', { className: 'nvtp-num', title: t('gpuTitle') }, fmtProcGpu(p, p.utilReported === true)),
|
|
139
179
|
h('td', { className: 'nvtp-num' }, fmtMemory(p.memoryUsed)),
|
|
140
180
|
h('td', { className: 'nvtp-num' }, p.cpuPercent === null || p.cpuPercent === undefined ? '—' : `${p.cpuPercent.toFixed(1)}%`),
|
|
141
181
|
h('td', { className: 'nvtp-num' }, fmtHostMemory(p.hostMemKib)),
|
|
@@ -155,8 +195,9 @@ window.__ModuleLoader__.load({
|
|
|
155
195
|
.nvtp-row{display:grid;grid-template-columns:64px 1fr 130px;gap:10px;align-items:center;font-size:12px}
|
|
156
196
|
.nvtp-row-label{color:var(--dsw-alias-label-secondary)}
|
|
157
197
|
.nvtp-row-value{text-align:right;font-variant-numeric:tabular-nums}
|
|
158
|
-
.nvtp-bar{height:8px;border-radius:4px;background:var(--dsw-alias-bg-layer-2);overflow:hidden}
|
|
159
|
-
.nvtp-bar-fill{height:100%;
|
|
198
|
+
.nvtp-bar{height:8px;border-radius:4px;background:var(--dsw-alias-bg-layer-2);overflow:hidden;display:flex}
|
|
199
|
+
.nvtp-bar-fill{height:100%;background:var(--dsw-alias-brand-primary);transition:width .4s ease;flex:none}
|
|
200
|
+
.nvtp-bar-other{background:var(--dsw-alias-state-idle-primary);opacity:.7}
|
|
160
201
|
.nvtp-ok .nvtp-bar-fill{background:var(--dsw-alias-brand-primary)}
|
|
161
202
|
.nvtp-warm .nvtp-bar-fill{background:var(--dsw-alias-state-warn-primary)}
|
|
162
203
|
.nvtp-hot .nvtp-bar-fill{background:var(--dsw-alias-state-error-primary)}
|
|
@@ -177,6 +218,11 @@ window.__ModuleLoader__.load({
|
|
|
177
218
|
.nvtp-empty-note{color:var(--dsw-alias-label-secondary);font-size:13px}
|
|
178
219
|
.nvtp-error{border:1px solid var(--dsw-alias-state-error-primary);border-radius:10px;padding:14px 16px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-1)}
|
|
179
220
|
.nvtp-error-label{color:var(--dsw-alias-state-error-primary);font-weight:600;margin-bottom:6px}
|
|
221
|
+
.nvtp-unit-error{display:flex;gap:10px;padding:8px 14px;font-size:12px;align-items:baseline}
|
|
222
|
+
.nvtp-unit-error .nvtp-error-label{margin-bottom:0;flex:none}
|
|
223
|
+
.nvtp-note{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-1)}
|
|
224
|
+
.nvtp-note-label{font-weight:600;flex:none}
|
|
225
|
+
.nvtp-chip{border:1px solid var(--dsw-alias-border-l2);border-radius:999px;padding:1px 8px;font-size:11px;color:var(--dsw-alias-label-secondary);flex:none}
|
|
180
226
|
`;
|
|
181
227
|
|
|
182
228
|
function pluralize(template, other, count) {
|
|
@@ -202,10 +248,12 @@ window.__ModuleLoader__.load({
|
|
|
202
248
|
const tick = async () => {
|
|
203
249
|
try {
|
|
204
250
|
const response = await fetch('/api/nvtop', { credentials: 'same-origin' });
|
|
205
|
-
const
|
|
251
|
+
const text = await response.text();
|
|
252
|
+
let body = null;
|
|
253
|
+
try { body = JSON.parse(text); } catch { body = null; }
|
|
206
254
|
if (!alive.current) return;
|
|
207
|
-
if (!response.ok || body.ok === false) {
|
|
208
|
-
setError(body?.message || `HTTP ${response.status}`);
|
|
255
|
+
if (!response.ok || body === null || body.ok === false) {
|
|
256
|
+
setError(body?.message || `HTTP ${response.status}${body === null && text ? `: ${text.slice(0, 80)}` : ''}`);
|
|
209
257
|
setData(null);
|
|
210
258
|
} else {
|
|
211
259
|
setError(null);
|
|
@@ -227,29 +275,70 @@ window.__ModuleLoader__.load({
|
|
|
227
275
|
};
|
|
228
276
|
}, []);
|
|
229
277
|
|
|
230
|
-
const
|
|
278
|
+
const units = data !== null && Array.isArray(data.units) && data.units.length > 0
|
|
279
|
+
? data.units
|
|
280
|
+
: data !== null
|
|
281
|
+
? [{
|
|
282
|
+
id: 'local',
|
|
283
|
+
title: translate('localUnit'),
|
|
284
|
+
remote: false,
|
|
285
|
+
gpus: data.gpus ?? [],
|
|
286
|
+
processes: data.processes ?? [],
|
|
287
|
+
}]
|
|
288
|
+
: [];
|
|
289
|
+
const multiUnit = units.length > 1;
|
|
290
|
+
const numberedUnits = units.map((unit, unitIdx) => ({ ...unit, unitIdx }));
|
|
291
|
+
const liveUnits = numberedUnits.filter((unit) => !unit.error);
|
|
292
|
+
const totalGpus = liveUnits.reduce((sum, unit) => sum + (unit.gpus?.length ?? 0), 0);
|
|
293
|
+
// One nvtop-style table across every unit; DEV is the unit index.
|
|
294
|
+
const mergedProcesses = liveUnits
|
|
295
|
+
.flatMap((unit) => (unit.processes ?? []).map((p) => ({
|
|
296
|
+
...p,
|
|
297
|
+
unitIdx: unit.unitIdx,
|
|
298
|
+
utilReported: unit.perProcessUtil === true,
|
|
299
|
+
})));
|
|
231
300
|
return h('div', { className: 'nvtp-page' },
|
|
232
301
|
h('style', null, CSS),
|
|
233
302
|
h('h1', { className: 'nvtp-title' }, translate('panel')),
|
|
234
303
|
h('div', { className: 'nvtp-sub' },
|
|
235
304
|
data === null && error === null ? translate('stale')
|
|
236
|
-
:
|
|
237
|
-
?
|
|
305
|
+
: totalGpus > 0
|
|
306
|
+
? (multiUnit
|
|
307
|
+
? `${pluralize(translate('units'), translate('unitsOther'), units.length)} · `
|
|
308
|
+
: '')
|
|
309
|
+
+ pluralize(translate('gpus'), translate('gpusOther'), totalGpus)
|
|
238
310
|
: ''),
|
|
239
311
|
error !== null
|
|
240
312
|
? h('div', { className: 'nvtp-error' },
|
|
241
313
|
h('div', { className: 'nvtp-error-label' }, translate('unavailable')),
|
|
242
314
|
h('div', null, error))
|
|
243
315
|
: null,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
316
|
+
numberedUnits
|
|
317
|
+
.filter((unit) => unit.error)
|
|
318
|
+
.map((unit) => h('div', { key: unit.id, className: 'nvtp-error nvtp-unit-error' },
|
|
319
|
+
h('span', { className: 'nvtp-error-label' }, `Spark #${unit.unitIdx}`),
|
|
320
|
+
h('span', null, unit.error))),
|
|
321
|
+
numberedUnits
|
|
322
|
+
.filter((unit) => !unit.error && unit.note)
|
|
323
|
+
.map((unit) => h('div', { key: unit.id + ':note', className: 'nvtp-note nvtp-unit-error' },
|
|
324
|
+
h('span', { className: 'nvtp-note-label' }, `Spark #${unit.unitIdx}`),
|
|
325
|
+
h('span', null, unit.note))),
|
|
326
|
+
h('div', { className: 'nvtp-grid' },
|
|
327
|
+
liveUnits.flatMap((unit) => (unit.gpus ?? []).map((gpu) => h(GpuCard, {
|
|
328
|
+
key: unit.id + ':' + gpu.index,
|
|
329
|
+
gpu,
|
|
330
|
+
t: translate,
|
|
331
|
+
unitTitle: multiUnit
|
|
332
|
+
? `Spark #${unit.unitIdx} · ${unit.remote === true ? 'SSH' : unit.title}`
|
|
333
|
+
: null,
|
|
334
|
+
})))),
|
|
335
|
+
h('section', { className: 'nvtp-procs' },
|
|
336
|
+
h('h2', null, translate('processes')),
|
|
337
|
+
h(ProcessTable, {
|
|
338
|
+
processes: mergedProcesses,
|
|
339
|
+
t: translate,
|
|
340
|
+
multiUnit,
|
|
341
|
+
})));
|
|
253
342
|
}
|
|
254
343
|
|
|
255
344
|
function PanelIcon(props) {
|
package/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { hostname } from 'node:os';
|
|
2
4
|
import Schema from '@deepseek-ai/schemastery';
|
|
3
5
|
|
|
4
6
|
const inject = ['connection', 'webServer'];
|
|
@@ -7,6 +9,17 @@ const inject = ['connection', 'webServer'];
|
|
|
7
9
|
const Config = Schema.object({
|
|
8
10
|
intervalMs: Schema.number().step(1).min(500).max(60000).default(2000)
|
|
9
11
|
.description('Recommended client poll interval in milliseconds (500-60000, default 2000)'),
|
|
12
|
+
peers: Schema.array(Schema.object({
|
|
13
|
+
host: Schema.string().required()
|
|
14
|
+
.description('SSH host of the peer unit (another DGX Spark or GPU host)'),
|
|
15
|
+
user: Schema.string()
|
|
16
|
+
.description('SSH user (default: the user dsh runs as)'),
|
|
17
|
+
port: Schema.number().default(22)
|
|
18
|
+
.description('SSH port'),
|
|
19
|
+
title: Schema.string()
|
|
20
|
+
.description('Display name for this unit (default: host)'),
|
|
21
|
+
})).default([])
|
|
22
|
+
.description('Peer units sampled over SSH; requires key-based auth (BatchMode)'),
|
|
10
23
|
});
|
|
11
24
|
|
|
12
25
|
const QUERY_FIELDS = [
|
|
@@ -28,20 +41,43 @@ const APP_FIELDS = ['pid', 'gpu_uuid', 'used_memory', 'process_name'].join(',');
|
|
|
28
41
|
const CACHE_MS = 1000;
|
|
29
42
|
/** nvidia-smi hard timeout per invocation. */
|
|
30
43
|
const SMI_TIMEOUT_MS = 5000;
|
|
44
|
+
/** SSH timeout per peer invocation (connect + command). */
|
|
45
|
+
const SSH_TIMEOUT_MS = 8000;
|
|
46
|
+
|
|
47
|
+
/** Marker names delimiting sections of the one-shot remote probe script. */
|
|
48
|
+
const REMOTE_SECTIONS = ['HOST', 'SMI', 'APPS', 'PMON', 'MEM'];
|
|
49
|
+
|
|
50
|
+
const REMOTE_PROBE = [
|
|
51
|
+
"printf '__NVTP_HOST__\\n'; hostname 2>/dev/null || echo unknown",
|
|
52
|
+
`printf '__NVTP_SMI__\\n'; nvidia-smi --query-gpu=${QUERY_FIELDS} --format=csv,noheader,nounits 2>/dev/null`,
|
|
53
|
+
`printf '__NVTP_APPS__\\n'; nvidia-smi --query-compute-apps=${APP_FIELDS} --format=csv,noheader,nounits 2>/dev/null`,
|
|
54
|
+
"printf '__NVTP_PMON__\\n'; nvidia-smi pmon -c 1 -s um 2>/dev/null",
|
|
55
|
+
"printf '__NVTP_MEM__\\n'; grep -E 'MemTotal|MemAvailable' /proc/meminfo 2>/dev/null",
|
|
56
|
+
].join('; ');
|
|
31
57
|
|
|
32
58
|
let cached;
|
|
33
59
|
let cachedAt = 0;
|
|
34
60
|
let sampling;
|
|
61
|
+
let peerConfig = [];
|
|
62
|
+
/** Peer refresh cadence; tracks the configured client interval. */
|
|
63
|
+
let pollBudgetMs = 2000;
|
|
35
64
|
|
|
36
|
-
function run(command, args) {
|
|
65
|
+
function run(command, args, timeout = SMI_TIMEOUT_MS) {
|
|
37
66
|
return new Promise((resolve, reject) => {
|
|
38
67
|
execFile(
|
|
39
68
|
command,
|
|
40
69
|
args,
|
|
41
|
-
{ timeout
|
|
42
|
-
(error, stdout) => {
|
|
43
|
-
if (error)
|
|
44
|
-
|
|
70
|
+
{ timeout, maxBuffer: 4 * 1024 * 1024 },
|
|
71
|
+
(error, stdout, stderr) => {
|
|
72
|
+
if (error) {
|
|
73
|
+
// Keep ssh's own diagnostics ("No route to host", "Permission denied")
|
|
74
|
+
// instead of the raw "Command failed: ssh -o ..." command line.
|
|
75
|
+
const detail = String(stderr ?? '').trim().split('\n').filter(Boolean).pop();
|
|
76
|
+
error.message = detail !== undefined && detail !== ''
|
|
77
|
+
? detail.slice(0, 120)
|
|
78
|
+
: String(error.message ?? error).slice(0, 120);
|
|
79
|
+
reject(error);
|
|
80
|
+
} else resolve(stdout);
|
|
45
81
|
},
|
|
46
82
|
);
|
|
47
83
|
});
|
|
@@ -51,6 +87,21 @@ function runSmi(args) {
|
|
|
51
87
|
return run('nvidia-smi', args);
|
|
52
88
|
}
|
|
53
89
|
|
|
90
|
+
/** One SSH command on a peer; key auth only (BatchMode never prompts). */
|
|
91
|
+
function sshRun(peer, script) {
|
|
92
|
+
const destination = peer.user !== undefined && peer.user !== null && peer.user !== ''
|
|
93
|
+
? `${peer.user}@${peer.host}`
|
|
94
|
+
: peer.host;
|
|
95
|
+
return run('ssh', [
|
|
96
|
+
'-o', 'BatchMode=yes',
|
|
97
|
+
'-o', 'ConnectTimeout=5',
|
|
98
|
+
'-o', 'StrictHostKeyChecking=accept-new',
|
|
99
|
+
'-p', String(peer.port ?? 22),
|
|
100
|
+
destination,
|
|
101
|
+
script,
|
|
102
|
+
], SSH_TIMEOUT_MS);
|
|
103
|
+
}
|
|
104
|
+
|
|
54
105
|
function splitCsv(line) {
|
|
55
106
|
const out = [];
|
|
56
107
|
let current = '';
|
|
@@ -77,41 +128,12 @@ function numeric(value) {
|
|
|
77
128
|
return Number.isFinite(n) ? n : null;
|
|
78
129
|
}
|
|
79
130
|
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const text = await run('ps', [
|
|
87
|
-
'-o', 'pid=,user=,%cpu=,rss=,args=',
|
|
88
|
-
'-p', unique.join(','),
|
|
89
|
-
]);
|
|
90
|
-
for (const line of text.split('\n')) {
|
|
91
|
-
if (line.trim() === '') continue;
|
|
92
|
-
const match = line.trim().match(/^(\d+)\s+(\S+)\s+([\d.]+)\s+(\d+)\s+(.*)$/);
|
|
93
|
-
if (match === null) continue;
|
|
94
|
-
details.set(Number(match[1]), {
|
|
95
|
-
user: match[2],
|
|
96
|
-
cpu: Number(match[3]),
|
|
97
|
-
rssKib: Number(match[4]),
|
|
98
|
-
command: match[5],
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
} catch {
|
|
102
|
-
// A process may exit between nvidia-smi and ps; leave its details absent.
|
|
103
|
-
}
|
|
104
|
-
return details;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async function sample() {
|
|
108
|
-
const [gpuText, appText] = await Promise.all([
|
|
109
|
-
runSmi(['--query-gpu', QUERY_FIELDS, '--format=csv,noheader,nounits']),
|
|
110
|
-
runSmi(['--query-compute-apps', APP_FIELDS, '--format=csv,noheader,nounits'])
|
|
111
|
-
.catch(() => ''),
|
|
112
|
-
]);
|
|
113
|
-
|
|
114
|
-
const gpus = gpuText
|
|
131
|
+
/**
|
|
132
|
+
* Parse `--query-gpu` CSV lines into raw GPU rows (no memory fallback yet).
|
|
133
|
+
* @internal exported for tests.
|
|
134
|
+
*/
|
|
135
|
+
function parseGpuCsv(text) {
|
|
136
|
+
return String(text ?? '')
|
|
115
137
|
.split('\n')
|
|
116
138
|
.map((line) => line.trim())
|
|
117
139
|
.filter((line) => line !== '')
|
|
@@ -130,10 +152,14 @@ async function sample() {
|
|
|
130
152
|
uuid: f[9] ?? '',
|
|
131
153
|
};
|
|
132
154
|
});
|
|
155
|
+
}
|
|
133
156
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Parse `--query-compute-apps` CSV lines: pid, gpu uuid, MiB, process name.
|
|
159
|
+
* @internal exported for tests.
|
|
160
|
+
*/
|
|
161
|
+
function parseAppsCsv(text) {
|
|
162
|
+
return String(text ?? '')
|
|
137
163
|
.split('\n')
|
|
138
164
|
.map((line) => line.trim())
|
|
139
165
|
.filter((line) => line !== '')
|
|
@@ -141,24 +167,206 @@ async function sample() {
|
|
|
141
167
|
const f = splitCsv(line);
|
|
142
168
|
return {
|
|
143
169
|
pid: numeric(f[0]) ?? 0,
|
|
144
|
-
|
|
170
|
+
uuid: f[1] ?? '',
|
|
145
171
|
memoryUsed: numeric(f[2]),
|
|
146
172
|
name: f[3] ?? '',
|
|
147
173
|
};
|
|
148
174
|
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Parse `nvidia-smi pmon -c 1` output into per-process utilisation rows.
|
|
179
|
+
*
|
|
180
|
+
* Each row is one (gpu, pid) context, so a process using several GPUs has one
|
|
181
|
+
* row per device. `sm` is the share of SM time the process used in the last
|
|
182
|
+
* sample window; `mem` is its memory-controller (bandwidth) utilisation. Both
|
|
183
|
+
* are null when the driver prints "-" (no activity / not reported).
|
|
184
|
+
* @internal exported for tests.
|
|
185
|
+
*/
|
|
186
|
+
function parsePmon(text) {
|
|
187
|
+
const rows = [];
|
|
188
|
+
for (const line of String(text ?? '').split('\n')) {
|
|
189
|
+
if (line.startsWith('#')) continue;
|
|
190
|
+
const match = line.trim().match(/^(\d+)\s+(\d+)\s+([CG])\s+(\S+)\s+(\S+)\s/);
|
|
191
|
+
if (match === null) continue;
|
|
192
|
+
rows.push({
|
|
193
|
+
device: Number(match[1]),
|
|
194
|
+
pid: Number(match[2]),
|
|
195
|
+
type: match[3],
|
|
196
|
+
sm: numeric(match[4]),
|
|
197
|
+
mem: numeric(match[5]),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return rows;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Sample per-process utilisation; empty when the driver does not support pmon. */
|
|
204
|
+
async function samplePmon(runner) {
|
|
205
|
+
try {
|
|
206
|
+
return parsePmon(await runner(['pmon', '-c', '1', '-s', 'um']));
|
|
207
|
+
} catch {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Parse MemTotal / MemAvailable from /proc/meminfo text.
|
|
214
|
+
* @internal exported for tests.
|
|
215
|
+
*/
|
|
216
|
+
function parseMeminfo(text) {
|
|
217
|
+
const out = { totalKib: null, availKib: null };
|
|
218
|
+
for (const line of String(text ?? '').split('\n')) {
|
|
219
|
+
let match = line.match(/^MemTotal:\s+(\d+)\s+kB/);
|
|
220
|
+
if (match !== null) out.totalKib = Number(match[1]);
|
|
221
|
+
match = line.match(/^MemAvailable:\s+(\d+)\s+kB/);
|
|
222
|
+
if (match !== null) out.availKib = Number(match[1]);
|
|
223
|
+
}
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Parse `ps -o pid=,user=,%cpu=,rss=,args=` output into a pid → details map. */
|
|
228
|
+
function parsePs(text) {
|
|
229
|
+
const details = new Map();
|
|
230
|
+
for (const line of String(text ?? '').split('\n')) {
|
|
231
|
+
if (line.trim() === '') continue;
|
|
232
|
+
const match = line.trim().match(/^(\d+)\s+(\S+)\s+([\d.]+)\s+(\d+)\s+(.*)$/);
|
|
233
|
+
if (match === null) continue;
|
|
234
|
+
details.set(Number(match[1]), {
|
|
235
|
+
user: match[2],
|
|
236
|
+
cpu: Number(match[3]),
|
|
237
|
+
rssKib: Number(match[4]),
|
|
238
|
+
command: match[5],
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return details;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** One `ps` call for every listed PID, executed through `execList` (local or ssh). */
|
|
245
|
+
async function processDetails(execList, pids) {
|
|
246
|
+
const unique = [...new Set(pids)].filter((pid) => Number.isInteger(pid) && pid > 0);
|
|
247
|
+
if (unique.length === 0) return new Map();
|
|
248
|
+
try {
|
|
249
|
+
const text = await execList(unique.join(','));
|
|
250
|
+
return parsePs(text);
|
|
251
|
+
} catch {
|
|
252
|
+
// A process may exit between nvidia-smi and ps; leave its details absent.
|
|
253
|
+
return new Map();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const PS_ARGS = ['-o', 'pid=,user=,%cpu=,rss=,args='];
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Fold raw samples into one unit: GPU rows with unified-memory fallback and the
|
|
261
|
+
* nvtop-style process table.
|
|
262
|
+
*
|
|
263
|
+
* Unified memory (DGX Spark GB10): nvidia-smi reports memory.used/total as
|
|
264
|
+
* [N/A] because the GPU shares the LPDDR5X pool with the CPU. Following the
|
|
265
|
+
* sparkDash approach, `used` then comes from the compute-apps sum and `total`
|
|
266
|
+
* from the OS-visible pool (MemTotal), with MemAvailable as the free figure.
|
|
267
|
+
* @param pmon - `nvidia-smi pmon` rows of this unit; per-process SM utilisation
|
|
268
|
+
* when the driver reports it, otherwise an empty list.
|
|
269
|
+
* @internal exported for tests.
|
|
270
|
+
*/
|
|
271
|
+
function assembleUnit({ title, remote, gpusRaw, apps, mem, psDetails, pmon = [] }) {
|
|
272
|
+
const poolTotalMib = mem.totalKib !== null ? mem.totalKib / 1024 : null;
|
|
273
|
+
const poolAvailMib = mem.availKib !== null ? mem.availKib / 1024 : null;
|
|
274
|
+
|
|
275
|
+
const appsByUuid = new Map();
|
|
276
|
+
let appsSumAll = 0;
|
|
277
|
+
for (const app of apps) {
|
|
278
|
+
appsByUuid.set(app.uuid, (appsByUuid.get(app.uuid) ?? 0) + (app.memoryUsed ?? 0));
|
|
279
|
+
appsSumAll += app.memoryUsed ?? 0;
|
|
280
|
+
}
|
|
149
281
|
|
|
150
|
-
const
|
|
282
|
+
const deviceOfUuid = new Map();
|
|
283
|
+
// pmon addresses devices by index; remember the index of each queried GPU uuid
|
|
284
|
+
// so a pmon row can be matched to the nvidia-smi gpu row it belongs to.
|
|
285
|
+
const uuidOfDevice = new Map();
|
|
286
|
+
const pmonSeen = new Set();
|
|
287
|
+
|
|
288
|
+
const gpus = gpusRaw.map((gpu) => {
|
|
289
|
+
const isSparkChip = /GB10|DGX\s*Spark/i.test(gpu.name ?? '');
|
|
290
|
+
let memoryUsed = gpu.memoryUsed;
|
|
291
|
+
let memoryTotal = gpu.memoryTotal;
|
|
292
|
+
let unified = false;
|
|
293
|
+
let memoryAvailable = null;
|
|
294
|
+
|
|
295
|
+
// GB10: nvidia-smi memory figures are N/A (or a misleading partial number
|
|
296
|
+
// on some driver builds) — the OS pool is the honest denominator.
|
|
297
|
+
if (isSparkChip || memoryTotal === null || memoryUsed === null) {
|
|
298
|
+
if (poolTotalMib !== null && (isSparkChip || memoryTotal === null)) {
|
|
299
|
+
unified = true;
|
|
300
|
+
memoryTotal = poolTotalMib;
|
|
301
|
+
memoryAvailable = poolAvailMib;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// GPU-allocated share of the pool: compute-apps sum (per device when the
|
|
305
|
+
// uuid maps, whole-box sum on a single-GPU unit without uuid match).
|
|
306
|
+
// Spark chips always prefer the sum: some driver builds report a
|
|
307
|
+
// misleading partial number instead of [N/A].
|
|
308
|
+
{
|
|
309
|
+
const perDevice = gpu.uuid !== '' ? appsByUuid.get(gpu.uuid) : undefined;
|
|
310
|
+
const appsForGpu = perDevice !== undefined
|
|
311
|
+
? perDevice
|
|
312
|
+
: (gpusRaw.length === 1 ? appsSumAll : 0);
|
|
313
|
+
if (memoryUsed === null || memoryUsed === 0
|
|
314
|
+
|| (isSparkChip && appsForGpu > 0 && appsForGpu !== memoryUsed)) {
|
|
315
|
+
memoryUsed = appsForGpu;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (gpu.uuid !== '') deviceOfUuid.set(gpu.uuid, gpu.index);
|
|
319
|
+
uuidOfDevice.set(gpu.index, gpu.uuid);
|
|
320
|
+
return {
|
|
321
|
+
...gpu,
|
|
322
|
+
memoryUsed,
|
|
323
|
+
memoryTotal,
|
|
324
|
+
unified,
|
|
325
|
+
memoryAvailable,
|
|
326
|
+
};
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Re-map app→device with the final uuid table (single-GPU Spark with an
|
|
330
|
+
// unmatched uuid still lands on device 0).
|
|
331
|
+
const entries = apps.map((app) => ({
|
|
332
|
+
pid: app.pid,
|
|
333
|
+
uuid: app.uuid,
|
|
334
|
+
device: deviceOfUuid.get(app.uuid)
|
|
335
|
+
?? (gpus.length === 1 ? gpus[0].index : null),
|
|
336
|
+
memoryUsed: app.memoryUsed,
|
|
337
|
+
name: app.name,
|
|
338
|
+
}));
|
|
339
|
+
|
|
340
|
+
// Per-process utilisation: a pmon row matches when both the pid and the
|
|
341
|
+
// device agree. The device check keeps a multi-GPU process from borrowing the
|
|
342
|
+
// SM figure it earned on another card.
|
|
343
|
+
const pmonKey = (device, pid) => `${device}:${pid}`;
|
|
344
|
+
const pmonRows = new Map();
|
|
345
|
+
for (const row of pmon) {
|
|
346
|
+
if (!uuidOfDevice.has(row.device)) continue;
|
|
347
|
+
const key = pmonKey(row.device, row.pid);
|
|
348
|
+
if (!pmonRows.has(key)) pmonRows.set(key, []);
|
|
349
|
+
pmonRows.get(key).push(row);
|
|
350
|
+
}
|
|
151
351
|
|
|
152
352
|
const processes = entries.map((entry) => {
|
|
153
|
-
const extra =
|
|
353
|
+
const extra = psDetails.get(entry.pid);
|
|
154
354
|
const device = gpus.find((gpu) => gpu.index === entry.device);
|
|
355
|
+
const rows = entry.device === null
|
|
356
|
+
? []
|
|
357
|
+
: (pmonRows.get(pmonKey(entry.device, entry.pid)) ?? []);
|
|
358
|
+
const measured = rows.find((row) => row.sm !== null) ?? rows[0];
|
|
359
|
+
if (measured !== undefined) pmonSeen.add(pmonKey(entry.device, entry.pid));
|
|
155
360
|
return {
|
|
156
361
|
pid: entry.pid,
|
|
157
362
|
user: extra?.user ?? null,
|
|
158
363
|
device: entry.device,
|
|
159
|
-
//
|
|
160
|
-
type: 'C',
|
|
161
|
-
|
|
364
|
+
// pmon knows C (compute) and G (graphics); compute-apps only lists C.
|
|
365
|
+
type: measured?.type ?? 'C',
|
|
366
|
+
// This process's own SM utilisation on this device. Null means the driver
|
|
367
|
+
// did not report it: it must never fall back to the whole-GPU figure.
|
|
368
|
+
gpuUtilization: measured !== undefined ? measured.sm : null,
|
|
369
|
+
gpuMemUtilization: measured !== undefined ? measured.mem : null,
|
|
162
370
|
memoryUsed: entry.memoryUsed,
|
|
163
371
|
cpuPercent: extra?.cpu ?? null,
|
|
164
372
|
hostMemKib: extra?.rssKib ?? null,
|
|
@@ -166,7 +374,140 @@ async function sample() {
|
|
|
166
374
|
};
|
|
167
375
|
});
|
|
168
376
|
|
|
169
|
-
return {
|
|
377
|
+
return {
|
|
378
|
+
title,
|
|
379
|
+
remote,
|
|
380
|
+
gpus,
|
|
381
|
+
processes,
|
|
382
|
+
hostMem: mem,
|
|
383
|
+
// False when the driver gave no per-process figures at all, so the UI can
|
|
384
|
+
// say the GPU column is unavailable rather than silently showing zeros.
|
|
385
|
+
perProcessUtil: pmonSeen.size > 0,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function sampleLocal() {
|
|
390
|
+
const [gpuText, appText, memText, pmon] = await Promise.all([
|
|
391
|
+
runSmi(['--query-gpu', QUERY_FIELDS, '--format=csv,noheader,nounits']),
|
|
392
|
+
runSmi(['--query-compute-apps', APP_FIELDS, '--format=csv,noheader,nounits'])
|
|
393
|
+
.catch(() => ''),
|
|
394
|
+
readFile('/proc/meminfo', 'utf8').catch(() => ''),
|
|
395
|
+
samplePmon((args) => runSmi(args)),
|
|
396
|
+
]);
|
|
397
|
+
const apps = parseAppsCsv(appText);
|
|
398
|
+
const psDetails = await processDetails(
|
|
399
|
+
(list) => run('ps', [...PS_ARGS, '-p', list]),
|
|
400
|
+
apps.map((app) => app.pid),
|
|
401
|
+
);
|
|
402
|
+
return assembleUnit({
|
|
403
|
+
title: hostname(),
|
|
404
|
+
remote: false,
|
|
405
|
+
gpusRaw: parseGpuCsv(gpuText),
|
|
406
|
+
apps,
|
|
407
|
+
mem: parseMeminfo(memText),
|
|
408
|
+
psDetails,
|
|
409
|
+
pmon,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** Split the one-shot remote probe output into its marked sections. */
|
|
414
|
+
function splitRemoteSections(text) {
|
|
415
|
+
const sections = {};
|
|
416
|
+
let current = null;
|
|
417
|
+
for (const line of String(text ?? '').split('\n')) {
|
|
418
|
+
const match = line.match(/^__NVTP_([A-Z]+)__$/);
|
|
419
|
+
if (match !== null && REMOTE_SECTIONS.includes(match[1])) {
|
|
420
|
+
current = match[1].toLowerCase();
|
|
421
|
+
sections[current] = [];
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (current !== null) sections[current].push(line);
|
|
425
|
+
}
|
|
426
|
+
for (const key of Object.keys(sections)) sections[key] = sections[key].join('\n');
|
|
427
|
+
return sections;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** Probe one peer over SSH; throws on failure (never returns an error unit). */
|
|
431
|
+
async function probePeer(peer) {
|
|
432
|
+
const probe = await sshRun(peer, REMOTE_PROBE);
|
|
433
|
+
const sections = splitRemoteSections(probe);
|
|
434
|
+
if (sections.smi === undefined) throw new Error('probe returned no markers');
|
|
435
|
+
const apps = parseAppsCsv(sections.apps ?? '');
|
|
436
|
+
const psDetails = await processDetails(
|
|
437
|
+
(list) => sshRun(peer, `ps ${PS_ARGS[0]} ${PS_ARGS[1]} -p ${list}`),
|
|
438
|
+
apps.map((app) => app.pid),
|
|
439
|
+
);
|
|
440
|
+
const unit = assembleUnit({
|
|
441
|
+
title: peer.title ?? ((sections.host ?? '').trim() || peer.host),
|
|
442
|
+
remote: true,
|
|
443
|
+
gpusRaw: parseGpuCsv(sections.smi ?? ''),
|
|
444
|
+
apps,
|
|
445
|
+
mem: parseMeminfo(sections.mem ?? ''),
|
|
446
|
+
psDetails,
|
|
447
|
+
pmon: parsePmon(sections.pmon ?? ''),
|
|
448
|
+
});
|
|
449
|
+
const complete = { id: peer.host, configuredTitle: peer.title ?? peer.host, ...unit };
|
|
450
|
+
if (complete.gpus.length === 0) {
|
|
451
|
+
complete.note = `no NVIDIA GPU detected on ${peer.host}`;
|
|
452
|
+
}
|
|
453
|
+
return complete;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Peer units never block the API response: each peer refreshes in the
|
|
458
|
+
* background on its own schedule, and every request reads the latest snapshot.
|
|
459
|
+
* A failed peer retries at most once per PEER_RETRY_MS.
|
|
460
|
+
*/
|
|
461
|
+
const peerState = new Map();
|
|
462
|
+
const peerRefreshing = new Set();
|
|
463
|
+
const PEER_RETRY_MS = 10000;
|
|
464
|
+
|
|
465
|
+
function refreshPeer(peer) {
|
|
466
|
+
const now = Date.now();
|
|
467
|
+
const state = peerState.get(peer.host);
|
|
468
|
+
if (state !== undefined && now < state.nextAt) return;
|
|
469
|
+
if (peerRefreshing.has(peer.host)) return;
|
|
470
|
+
peerRefreshing.add(peer.host);
|
|
471
|
+
probePeer(peer)
|
|
472
|
+
.then((unit) => {
|
|
473
|
+
peerState.set(peer.host, { unit, error: null, at: Date.now(), nextAt: Date.now() + pollBudgetMs });
|
|
474
|
+
})
|
|
475
|
+
.catch((error) => {
|
|
476
|
+
peerState.set(peer.host, {
|
|
477
|
+
unit: null,
|
|
478
|
+
error: `SSH ${peer.host}: ${error?.message ?? String(error)}`,
|
|
479
|
+
at: Date.now(),
|
|
480
|
+
nextAt: Date.now() + PEER_RETRY_MS,
|
|
481
|
+
});
|
|
482
|
+
})
|
|
483
|
+
.finally(() => peerRefreshing.delete(peer.host));
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Latest view of one peer: last-good data, the last error, or a connecting note. */
|
|
487
|
+
function peerSnapshot(peer) {
|
|
488
|
+
refreshPeer(peer);
|
|
489
|
+
const state = peerState.get(peer.host);
|
|
490
|
+
const fallbackTitle = peer.title ?? peer.host;
|
|
491
|
+
if (state === undefined) {
|
|
492
|
+
return { id: peer.host, title: fallbackTitle, remote: true, error: `SSH ${peer.host}: connecting…` };
|
|
493
|
+
}
|
|
494
|
+
if (state.error !== null) {
|
|
495
|
+
return { id: peer.host, title: fallbackTitle, remote: true, error: state.error };
|
|
496
|
+
}
|
|
497
|
+
return state.unit;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
async function sample() {
|
|
501
|
+
const local = await sampleLocal();
|
|
502
|
+
const units = [{ id: 'local', ...local }, ...peerConfig.map((peer) => peerSnapshot(peer))];
|
|
503
|
+
return {
|
|
504
|
+
ok: true,
|
|
505
|
+
sampledAt: Date.now(),
|
|
506
|
+
units,
|
|
507
|
+
// Backwards-compatible top-level view of the local unit.
|
|
508
|
+
gpus: local.gpus,
|
|
509
|
+
processes: local.processes,
|
|
510
|
+
};
|
|
170
511
|
}
|
|
171
512
|
|
|
172
513
|
function jsonResponse(body) {
|
|
@@ -209,6 +550,13 @@ async function fetchStats() {
|
|
|
209
550
|
*/
|
|
210
551
|
function apply(ctx, config) {
|
|
211
552
|
const intervalMs = config?.intervalMs ?? 2000;
|
|
553
|
+
peerConfig = Array.isArray(config?.peers) ? config.peers : [];
|
|
554
|
+
pollBudgetMs = Math.max(1000, intervalMs);
|
|
555
|
+
// Drop cached state for peers that are no longer configured.
|
|
556
|
+
const configuredHosts = new Set(peerConfig.map((peer) => peer.host));
|
|
557
|
+
for (const host of peerState.keys()) {
|
|
558
|
+
if (!configuredHosts.has(host)) peerState.delete(host);
|
|
559
|
+
}
|
|
212
560
|
const dispose = ctx.connection.registerFetchRoute(ctx, {
|
|
213
561
|
path: '/api/nvtop',
|
|
214
562
|
methods: ['GET'],
|
|
@@ -230,4 +578,15 @@ function apply(ctx, config) {
|
|
|
230
578
|
ctx.effect(() => dispose, 'dsh-nvtop: /api/nvtop stats route');
|
|
231
579
|
}
|
|
232
580
|
|
|
233
|
-
export {
|
|
581
|
+
export {
|
|
582
|
+
Config,
|
|
583
|
+
apply,
|
|
584
|
+
inject,
|
|
585
|
+
// @internal test hooks
|
|
586
|
+
parseGpuCsv,
|
|
587
|
+
parseAppsCsv,
|
|
588
|
+
parseMeminfo,
|
|
589
|
+
parsePmon,
|
|
590
|
+
assembleUnit,
|
|
591
|
+
splitRemoteSections,
|
|
592
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-nvtop-panel",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "nvtop-style live GPU dashboard panel for the DeepSeek Harness (DSH) Web UI: per-GPU utilization/memory/temperature/power cards plus a full nvtop-like process table (PID, USER, DEV, TYPE, GPU, GPU MEM, CPU, HOST MEM, Command).",
|
|
6
|
+
"description": "nvtop-style live GPU dashboard panel for the DeepSeek Harness (DSH) Web UI: per-GPU utilization/memory/temperature/power cards plus a full nvtop-like process table (PID, USER, DEV, TYPE, GPU, GPU MEM, CPU, HOST MEM, Command). DGX Spark (GB10) unified memory supported; daisy-chained units monitored over SSH.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@deepseek-ai/schemastery": "^3.19.0"
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"LICENSE"
|
|
34
34
|
],
|
|
35
35
|
"dsh": {
|
|
36
|
-
"bundle": {
|
|
36
|
+
"bundle": {
|
|
37
|
+
"patch": "./cordis.patch.yml"
|
|
38
|
+
},
|
|
37
39
|
"client": {
|
|
38
40
|
"platform": "web",
|
|
39
41
|
"immediately": true,
|