dsh-remote-vs 0.18.0 → 0.19.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.en.md +12 -2
- package/README.md +10 -2
- package/lib/client.js +1075 -9
- package/lib/index.js +381 -4
- 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/protocol.d.ts +54 -0
- package/package.json +36 -36
- 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/protocol.ts +58 -1
- package/src/routes.ts +47 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sidebar monitor: live CPU / memory / disk / network / temperature for one
|
|
3
|
+
* host (or every host at once).
|
|
4
|
+
*
|
|
5
|
+
* Costs are shaped by the plugin's channel budget: the panel polls only while
|
|
6
|
+
* it is the visible view AND the page is visible (5 s), the Host reuses a
|
|
7
|
+
* sample for a few seconds, and a per-alias in-flight set means a manual
|
|
8
|
+
* refresh cannot open a second channel for a host that is already sampling.
|
|
9
|
+
* The first sample is honest about deltas: CPU% and the network rate read
|
|
10
|
+
* "unknown" until a second sample exists.
|
|
11
|
+
*/
|
|
12
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
13
|
+
import type { RemoteHostMetrics, RemoteHostSummary, RemoteMetricsState } from '../protocol.ts'
|
|
14
|
+
import { RemoteApiError, api } from './api.ts'
|
|
15
|
+
import {
|
|
16
|
+
appendMetrics,
|
|
17
|
+
combineDomain,
|
|
18
|
+
emptyHistory,
|
|
19
|
+
formatAgeShort,
|
|
20
|
+
formatCapacity,
|
|
21
|
+
formatPercent,
|
|
22
|
+
formatRate,
|
|
23
|
+
formatTemperature,
|
|
24
|
+
formatUptime,
|
|
25
|
+
metricTone,
|
|
26
|
+
placeholderMetrics,
|
|
27
|
+
sparklinePath,
|
|
28
|
+
type MetricHistory,
|
|
29
|
+
} from './metrics-model.ts'
|
|
30
|
+
import { useExplorer } from './store.tsx'
|
|
31
|
+
import { optionStyle } from './ui.tsx'
|
|
32
|
+
import { IconButton, IconRefresh, MiniSpinner, Segmented } from './vsc/kit.tsx'
|
|
33
|
+
|
|
34
|
+
/** Visible-panel poll cadence. The Host's own reuse window is shorter (3 s). */
|
|
35
|
+
export const MONITOR_POLL_MS = 5_000
|
|
36
|
+
|
|
37
|
+
const SCOPE_KEY = 'dsh-remote-vs.monitor.scope'
|
|
38
|
+
const INTERVAL_KEY = 'dsh-remote-vs.monitor.interval'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The refresh-interval setting.
|
|
42
|
+
*
|
|
43
|
+
* `MONITOR_POLL_MS` stays the default and the documented cadence; the other
|
|
44
|
+
* choices exist for slow links / many hosts. The value is validated against
|
|
45
|
+
* this list on read, so a hand-edited localStorage value cannot turn the poll
|
|
46
|
+
* into a 1 ms loop.
|
|
47
|
+
*/
|
|
48
|
+
export const INTERVAL_CHOICES = [5_000, 10_000, 30_000] as const
|
|
49
|
+
|
|
50
|
+
function readIntervalMs(): number {
|
|
51
|
+
try {
|
|
52
|
+
const saved = Number(localStorage.getItem(INTERVAL_KEY))
|
|
53
|
+
if (INTERVAL_CHOICES.includes(saved as (typeof INTERVAL_CHOICES)[number])) return saved
|
|
54
|
+
} catch {
|
|
55
|
+
// Private mode: the default stands.
|
|
56
|
+
}
|
|
57
|
+
return MONITOR_POLL_MS
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function saveIntervalMs(value: number): void {
|
|
61
|
+
try {
|
|
62
|
+
localStorage.setItem(INTERVAL_KEY, String(value))
|
|
63
|
+
} catch {
|
|
64
|
+
// Ignore.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* One scope pick: the workspace's host, one named host, or every host.
|
|
70
|
+
*
|
|
71
|
+
* Persisted as a string so a reload comes back to the same subject; the
|
|
72
|
+
* `host:` prefix keeps an alias literally named "all" unambiguous.
|
|
73
|
+
*/
|
|
74
|
+
type MonitorScope = 'current' | 'all' | `host:${string}`
|
|
75
|
+
|
|
76
|
+
function readScope(): MonitorScope {
|
|
77
|
+
try {
|
|
78
|
+
const saved = localStorage.getItem(SCOPE_KEY)
|
|
79
|
+
if (saved === 'current' || saved === 'all') return saved
|
|
80
|
+
if (saved !== null && saved.startsWith('host:') && saved.length > 'host:'.length) {
|
|
81
|
+
return saved as MonitorScope
|
|
82
|
+
}
|
|
83
|
+
} catch {
|
|
84
|
+
// Private mode: the pick simply does not survive a reload.
|
|
85
|
+
}
|
|
86
|
+
return 'current'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function saveScope(scope: MonitorScope): void {
|
|
90
|
+
try {
|
|
91
|
+
localStorage.setItem(SCOPE_KEY, scope)
|
|
92
|
+
} catch {
|
|
93
|
+
// Ignore.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function currentHostAlias(hosts: RemoteHostSummary[], workspaceAlias: string): string {
|
|
98
|
+
if (workspaceAlias !== '' && hosts.some(host => host.alias === workspaceAlias)) return workspaceAlias
|
|
99
|
+
return hosts[0]?.alias ?? ''
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The aliases one scope samples; an unknown stored host falls back to current. */
|
|
103
|
+
function resolveAliases(scope: MonitorScope, hosts: RemoteHostSummary[], workspaceAlias: string): string[] {
|
|
104
|
+
if (scope === 'all') return hosts.map(host => host.alias)
|
|
105
|
+
if (scope.startsWith('host:')) {
|
|
106
|
+
const alias = scope.slice('host:'.length)
|
|
107
|
+
if (hosts.some(host => host.alias === alias)) return [alias]
|
|
108
|
+
}
|
|
109
|
+
const current = currentHostAlias(hosts, workspaceAlias)
|
|
110
|
+
return current === '' ? [] : [current]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** One rail icon: a screen with a pulse line. */
|
|
114
|
+
export function IconMonitor(props: { size?: number }): ReactNode {
|
|
115
|
+
const size = props.size ?? 16
|
|
116
|
+
return (
|
|
117
|
+
<svg
|
|
118
|
+
width={size}
|
|
119
|
+
height={size}
|
|
120
|
+
viewBox="0 0 16 16"
|
|
121
|
+
fill="none"
|
|
122
|
+
stroke="currentColor"
|
|
123
|
+
strokeWidth="1.4"
|
|
124
|
+
strokeLinecap="round"
|
|
125
|
+
strokeLinejoin="round"
|
|
126
|
+
aria-hidden="true"
|
|
127
|
+
>
|
|
128
|
+
<rect x="1.6" y="2.6" width="12.8" height="9" rx="1.4" />
|
|
129
|
+
<path d="M5.2 7.6h1.6l1.1-2.2 1.4 4 1-1.8h1.5" />
|
|
130
|
+
<path d="M5.6 14.2h4.8" />
|
|
131
|
+
</svg>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function IconPause(props: { size?: number }): ReactNode {
|
|
136
|
+
const size = props.size ?? 14
|
|
137
|
+
return (
|
|
138
|
+
<svg width={size} height={size} viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
|
139
|
+
<rect x="4.2" y="3" width="2.4" height="10" rx="0.8" />
|
|
140
|
+
<rect x="9.4" y="3" width="2.4" height="10" rx="0.8" />
|
|
141
|
+
</svg>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function IconPlay(props: { size?: number }): ReactNode {
|
|
146
|
+
const size = props.size ?? 14
|
|
147
|
+
return (
|
|
148
|
+
<svg width={size} height={size} viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
|
149
|
+
<path d="M5 3.2v9.6c0 .5.6.8 1 .5l7-4.6a.6.6 0 0 0 0-1l-7-4.6c-.4-.3-1 0-1 .5Z" />
|
|
150
|
+
</svg>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Sliders: the panel's own settings (refresh interval). */
|
|
155
|
+
function IconSettings(props: { size?: number }): ReactNode {
|
|
156
|
+
const size = props.size ?? 14
|
|
157
|
+
return (
|
|
158
|
+
<svg
|
|
159
|
+
width={size}
|
|
160
|
+
height={size}
|
|
161
|
+
viewBox="0 0 16 16"
|
|
162
|
+
fill="none"
|
|
163
|
+
stroke="currentColor"
|
|
164
|
+
strokeWidth="1.4"
|
|
165
|
+
strokeLinecap="round"
|
|
166
|
+
aria-hidden="true"
|
|
167
|
+
>
|
|
168
|
+
<path d="M2.4 4.6h4.2M9.4 4.6h4.2" />
|
|
169
|
+
<path d="M2.4 8h2.2M7.4 8h6.2" />
|
|
170
|
+
<path d="M2.4 11.4h4.2M9.4 11.4h4.2" />
|
|
171
|
+
<circle cx="8" cy="4.6" r="1.3" />
|
|
172
|
+
<circle cx="6" cy="8" r="1.3" />
|
|
173
|
+
<circle cx="8" cy="11.4" r="1.3" />
|
|
174
|
+
</svg>
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** One gauge tile: value + bar (the bar is absent when the value is unknown). */
|
|
179
|
+
function Gauge(props: {
|
|
180
|
+
label: string
|
|
181
|
+
value: string
|
|
182
|
+
sub?: string | undefined
|
|
183
|
+
percent: number | null
|
|
184
|
+
}): ReactNode {
|
|
185
|
+
return (
|
|
186
|
+
<div className="rvs-monitor-tile">
|
|
187
|
+
<div className="rvs-monitor-tile-label">{props.label}</div>
|
|
188
|
+
<div className="rvs-monitor-tile-value">{props.value}</div>
|
|
189
|
+
{props.percent !== null && (
|
|
190
|
+
<div className="rvs-monitor-bar" aria-hidden="true">
|
|
191
|
+
<span
|
|
192
|
+
className={`rvs-monitor-bar-fill ${metricTone(props.percent)}`}
|
|
193
|
+
style={{ width: `${Math.max(0, Math.min(100, props.percent))}%` }}
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
)}
|
|
197
|
+
{props.sub !== undefined && <div className="rvs-monitor-tile-sub">{props.sub}</div>}
|
|
198
|
+
</div>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** One small static fact (temperature, uptime, load, network). */
|
|
203
|
+
function Fact(props: { label: string; value: string; title?: string }): ReactNode {
|
|
204
|
+
return (
|
|
205
|
+
<div className="rvs-monitor-fact" title={props.title}>
|
|
206
|
+
<div className="rvs-monitor-fact-label">{props.label}</div>
|
|
207
|
+
<div className="rvs-monitor-fact-value">{props.value}</div>
|
|
208
|
+
</div>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* One sparkline card.
|
|
214
|
+
*
|
|
215
|
+
* The area under the line is a gradient of `currentColor`, so the same markup
|
|
216
|
+
* follows the theme and the `.rvs-monitor-spark.cpu/.mem/...` class colours the
|
|
217
|
+
* line without any inline palette.
|
|
218
|
+
*/
|
|
219
|
+
function Spark(props: {
|
|
220
|
+
label: string
|
|
221
|
+
values: readonly number[]
|
|
222
|
+
valuesAlt?: readonly number[] | undefined
|
|
223
|
+
tone: string
|
|
224
|
+
empty: string
|
|
225
|
+
}): ReactNode {
|
|
226
|
+
const rawId = useId()
|
|
227
|
+
// Deliberately NOT `rvs-monitor-*`: that prefix is the panel's CSS class
|
|
228
|
+
// namespace, and the gate checks that every such class has a rule. This id is
|
|
229
|
+
// an SVG fragment reference, not a class.
|
|
230
|
+
const gradientId = `rvs-grad-${rawId.replace(/[^A-Za-z0-9_-]/g, '')}`
|
|
231
|
+
const altValues = props.valuesAlt ?? []
|
|
232
|
+
// ONE y-domain for both series: independently auto-scaled RX/TX lines would
|
|
233
|
+
// look identical even when one is 100× the other (a misleading chart). The
|
|
234
|
+
// shared domain is the bug fix this argument exists for.
|
|
235
|
+
const domain = altValues.length === 0 ? undefined : combineDomain(props.values, altValues)
|
|
236
|
+
const path = sparklinePath(props.values, 100, 28, domain)
|
|
237
|
+
const altPath = altValues.length === 0 ? '' : sparklinePath(altValues, 100, 28, domain)
|
|
238
|
+
/**
|
|
239
|
+
* A single sample is drawn as a DOT. Filling the area from a one-point path
|
|
240
|
+
* (`M100,14L100,28L0,28Z`) used to paint a full-width wedge and imply a trend
|
|
241
|
+
* that does not exist yet.
|
|
242
|
+
*/
|
|
243
|
+
const singleSample = props.values.length < 2
|
|
244
|
+
return (
|
|
245
|
+
<div className={`rvs-monitor-spark ${props.tone}`}>
|
|
246
|
+
<div className="rvs-monitor-spark-head">
|
|
247
|
+
<span className="rvs-monitor-spark-label">{props.label}</span>
|
|
248
|
+
{altValues.length > 0 && (
|
|
249
|
+
<span className="rvs-monitor-spark-legend" aria-hidden="true">
|
|
250
|
+
<span className="rvs-monitor-spark-key"><i className="rvs-monitor-spark-line rx" />↓</span>
|
|
251
|
+
<span className="rvs-monitor-spark-key"><i className="rvs-monitor-spark-line tx" />↑</span>
|
|
252
|
+
</span>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
{path === '' ? (
|
|
256
|
+
<div className="rvs-monitor-spark-empty">{props.empty}</div>
|
|
257
|
+
) : (
|
|
258
|
+
<svg viewBox="0 0 100 28" preserveAspectRatio="none" aria-hidden="true">
|
|
259
|
+
{singleSample ? (
|
|
260
|
+
// cx=98 with r=2 stays inside the 0–100 viewBox: `cx=100` clipped
|
|
261
|
+
// the dot to a half-visible sliver at the right edge.
|
|
262
|
+
<circle cx="98" cy="14" r="2" fill="currentColor" />
|
|
263
|
+
) : (
|
|
264
|
+
<>
|
|
265
|
+
<defs>
|
|
266
|
+
<linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
|
|
267
|
+
<stop offset="0%" stopColor="currentColor" stopOpacity="0.22" />
|
|
268
|
+
<stop offset="100%" stopColor="currentColor" stopOpacity="0" />
|
|
269
|
+
</linearGradient>
|
|
270
|
+
</defs>
|
|
271
|
+
<path d={`${path}L100,28L0,28Z`} fill={`url(#${gradientId})`} />
|
|
272
|
+
{altPath !== '' && (
|
|
273
|
+
<path d={altPath} fill="none" stroke="currentColor" strokeWidth="1.3" strokeDasharray="3 3" opacity="0.6" vectorEffect="non-scaling-stroke" />
|
|
274
|
+
)}
|
|
275
|
+
<path d={path} fill="none" stroke="currentColor" strokeWidth="1.5" vectorEffect="non-scaling-stroke" />
|
|
276
|
+
</>
|
|
277
|
+
)}
|
|
278
|
+
</svg>
|
|
279
|
+
)}
|
|
280
|
+
</div>
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function stateLabelOf(state: RemoteMetricsState, t: (key: string) => string): string {
|
|
285
|
+
if (state === 'ok') return t('monitor.stateOk')
|
|
286
|
+
if (state === 'error') return t('monitor.stateError')
|
|
287
|
+
return t('monitor.stateUnknown')
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function hostLabelOf(alias: string, hosts: RemoteHostSummary[]): string {
|
|
291
|
+
const host = hosts.find(item => item.alias === alias)
|
|
292
|
+
return host === undefined ? alias : `${host.user}@${host.host}:${host.port}`
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function MonitorView(props: {
|
|
296
|
+
t: (key: string) => string
|
|
297
|
+
hosts: RemoteHostSummary[]
|
|
298
|
+
visible: boolean
|
|
299
|
+
}): ReactNode {
|
|
300
|
+
const t = props.t
|
|
301
|
+
const store = useExplorer()
|
|
302
|
+
const workspaceAlias = store.workspace?.alias ?? ''
|
|
303
|
+
const [scope, setScope] = useState<MonitorScope>(readScope)
|
|
304
|
+
const [intervalMs, setIntervalMs] = useState<number>(readIntervalMs)
|
|
305
|
+
const [settingsOpen, setSettingsOpen] = useState(false)
|
|
306
|
+
const [samples, setSamples] = useState<Record<string, RemoteHostMetrics>>({})
|
|
307
|
+
const [histories, setHistories] = useState<Record<string, MetricHistory>>({})
|
|
308
|
+
const [paused, setPaused] = useState(false)
|
|
309
|
+
const [refreshing, setRefreshing] = useState(false)
|
|
310
|
+
/** Aliases with a sample request in flight (a second interval tick is a no-op). */
|
|
311
|
+
const inFlight = useRef<Set<string>>(new Set())
|
|
312
|
+
const alive = useRef(true)
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
alive.current = true
|
|
315
|
+
return () => {
|
|
316
|
+
alive.current = false
|
|
317
|
+
}
|
|
318
|
+
}, [])
|
|
319
|
+
|
|
320
|
+
const aliases = useMemo(
|
|
321
|
+
() => resolveAliases(scope, props.hosts, workspaceAlias),
|
|
322
|
+
[scope, props.hosts, workspaceAlias],
|
|
323
|
+
)
|
|
324
|
+
/** Stable identity for the effect: a store publish must not restart the timer. */
|
|
325
|
+
const aliasesKey = aliases.join('|')
|
|
326
|
+
const aliasesRef = useRef<string[]>(aliases)
|
|
327
|
+
aliasesRef.current = aliases
|
|
328
|
+
|
|
329
|
+
const currentAlias = currentHostAlias(props.hosts, workspaceAlias)
|
|
330
|
+
const selectValue: string = useMemo(() => {
|
|
331
|
+
if (scope === 'all') return 'all'
|
|
332
|
+
if (scope.startsWith('host:')) {
|
|
333
|
+
const alias = scope.slice('host:'.length)
|
|
334
|
+
if (props.hosts.some(host => host.alias === alias)) return scope
|
|
335
|
+
}
|
|
336
|
+
return 'current'
|
|
337
|
+
}, [scope, props.hosts])
|
|
338
|
+
|
|
339
|
+
const load = useCallback(async (targets: string[], force: boolean): Promise<void> => {
|
|
340
|
+
await Promise.all(targets.map(async (alias) => {
|
|
341
|
+
if (inFlight.current.has(alias)) return
|
|
342
|
+
inFlight.current.add(alias)
|
|
343
|
+
try {
|
|
344
|
+
const metrics = await api.hostMetrics(alias, force)
|
|
345
|
+
if (!alive.current) return
|
|
346
|
+
setSamples(previous => ({ ...previous, [alias]: metrics }))
|
|
347
|
+
setHistories(previous => ({ ...previous, [alias]: appendMetrics(previous[alias] ?? emptyHistory(), metrics) }))
|
|
348
|
+
} catch (error) {
|
|
349
|
+
if (!alive.current) return
|
|
350
|
+
const reason = error instanceof RemoteApiError ? error.message : String(error)
|
|
351
|
+
setSamples(previous => ({ ...previous, [alias]: placeholderMetrics(alias, 'error', reason) }))
|
|
352
|
+
} finally {
|
|
353
|
+
inFlight.current.delete(alias)
|
|
354
|
+
}
|
|
355
|
+
}))
|
|
356
|
+
}, [])
|
|
357
|
+
|
|
358
|
+
// The ONLY polling site: visible panel + visible page. A parked rail panel
|
|
359
|
+
// and a background tab both stop asking, so the monitor never becomes the
|
|
360
|
+
// plugin's traffic source while the user is looking at files or the terminal.
|
|
361
|
+
// `tick` is the single place that decides visibility, so both the immediate
|
|
362
|
+
// sample and the interval sample share the same guard (and returning to the
|
|
363
|
+
// tab samples at once instead of waiting out the interval).
|
|
364
|
+
useEffect(() => {
|
|
365
|
+
if (!props.visible || paused) return
|
|
366
|
+
const targets = aliasesRef.current
|
|
367
|
+
if (targets.length === 0) return
|
|
368
|
+
const tick = (): void => {
|
|
369
|
+
if (document.hidden) return
|
|
370
|
+
void load(aliasesRef.current, false)
|
|
371
|
+
}
|
|
372
|
+
tick()
|
|
373
|
+
const timer = window.setInterval(tick, intervalMs)
|
|
374
|
+
const onVisibilityChange = (): void => {
|
|
375
|
+
if (!document.hidden) tick()
|
|
376
|
+
}
|
|
377
|
+
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
378
|
+
return () => {
|
|
379
|
+
document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
380
|
+
window.clearInterval(timer)
|
|
381
|
+
}
|
|
382
|
+
}, [props.visible, paused, aliasesKey, intervalMs, load])
|
|
383
|
+
|
|
384
|
+
const refresh = useCallback((): void => {
|
|
385
|
+
const targets = aliasesRef.current
|
|
386
|
+
if (targets.length === 0) return
|
|
387
|
+
setRefreshing(true)
|
|
388
|
+
void load(targets, true).finally(() => {
|
|
389
|
+
if (alive.current) setRefreshing(false)
|
|
390
|
+
})
|
|
391
|
+
}, [load])
|
|
392
|
+
|
|
393
|
+
const choose = useCallback((next: string): void => {
|
|
394
|
+
const value = next as MonitorScope
|
|
395
|
+
setScope(value)
|
|
396
|
+
saveScope(value)
|
|
397
|
+
}, [])
|
|
398
|
+
|
|
399
|
+
const chooseInterval = useCallback((next: string): void => {
|
|
400
|
+
const value = Number(next)
|
|
401
|
+
if (!INTERVAL_CHOICES.includes(value as (typeof INTERVAL_CHOICES)[number])) return
|
|
402
|
+
setIntervalMs(value)
|
|
403
|
+
saveIntervalMs(value)
|
|
404
|
+
}, [])
|
|
405
|
+
|
|
406
|
+
const unknown = t('monitor.unknown')
|
|
407
|
+
const stateLabel = (state: RemoteMetricsState): string => stateLabelOf(state, t)
|
|
408
|
+
const ageLabel = (metrics: RemoteHostMetrics): string => {
|
|
409
|
+
const age = Date.now() - metrics.sampledAt
|
|
410
|
+
if (age < 1_500) return t('monitor.justNow')
|
|
411
|
+
return t('monitor.updatedAgo').replace('{age}', formatAgeShort(age))
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const renderDetail = (alias: string): ReactNode => {
|
|
415
|
+
const metrics = samples[alias]
|
|
416
|
+
if (metrics === undefined) {
|
|
417
|
+
return (
|
|
418
|
+
<div className="rvs-empty">
|
|
419
|
+
{props.visible ? (<><MiniSpinner /> {t('monitor.loading')}</>) : t('monitor.noData')}
|
|
420
|
+
</div>
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
const state = metrics.state
|
|
424
|
+
const label = stateLabel(state)
|
|
425
|
+
const history = histories[alias] ?? emptyHistory()
|
|
426
|
+
const memPercent = metrics.memPercent
|
|
427
|
+
const diskPercent = metrics.diskPercent
|
|
428
|
+
const loadText = metrics.load1 === null || metrics.load5 === null || metrics.load15 === null
|
|
429
|
+
? unknown
|
|
430
|
+
: [metrics.load1, metrics.load5, metrics.load15].map(value => value.toFixed(2)).join(' / ')
|
|
431
|
+
const netText = metrics.netRxBps === null && metrics.netTxBps === null
|
|
432
|
+
? unknown
|
|
433
|
+
: `${metrics.netRxBps === null ? unknown : formatRate(metrics.netRxBps)} ↓ / ${metrics.netTxBps === null ? unknown : formatRate(metrics.netTxBps)} ↑`
|
|
434
|
+
return (
|
|
435
|
+
<div className={`rvs-monitor-card ${state}`}>
|
|
436
|
+
<div className="rvs-monitor-head">
|
|
437
|
+
{/* The state word is right below this dot; announcing it twice is noise. */}
|
|
438
|
+
<span className={`rvs-monitor-dot ${state}`} aria-hidden="true" />
|
|
439
|
+
<span className="rvs-monitor-title" title={alias}>{alias}</span>
|
|
440
|
+
<span className="rvs-monitor-conn" title={hostLabelOf(alias, props.hosts)}>{hostLabelOf(alias, props.hosts)}</span>
|
|
441
|
+
</div>
|
|
442
|
+
<div className="rvs-monitor-sub">
|
|
443
|
+
<span className={`rvs-monitor-state ${state}`}>{label}</span>
|
|
444
|
+
<span className="rvs-monitor-age">{ageLabel(metrics)}</span>
|
|
445
|
+
{metrics.reason !== undefined && (
|
|
446
|
+
<span className="rvs-monitor-reason" title={metrics.reason}>{t('monitor.reason').replace('{reason}', metrics.reason)}</span>
|
|
447
|
+
)}
|
|
448
|
+
</div>
|
|
449
|
+
{state === 'ok' ? (
|
|
450
|
+
<>
|
|
451
|
+
<div className="rvs-monitor-grid">
|
|
452
|
+
<Gauge
|
|
453
|
+
label={t('monitor.cpu')}
|
|
454
|
+
value={metrics.cpuPercent === null ? unknown : formatPercent(metrics.cpuPercent)}
|
|
455
|
+
percent={metrics.cpuPercent}
|
|
456
|
+
sub={metrics.cpuCores === null
|
|
457
|
+
? (metrics.cpuPercent === null ? t('monitor.warming') : undefined)
|
|
458
|
+
: t('monitor.cores').replace('{count}', String(metrics.cpuCores))}
|
|
459
|
+
/>
|
|
460
|
+
<Gauge
|
|
461
|
+
label={t('monitor.ram')}
|
|
462
|
+
value={memPercent === null ? unknown : formatPercent(memPercent)}
|
|
463
|
+
percent={memPercent}
|
|
464
|
+
sub={metrics.memUsedBytes === null || metrics.memTotalBytes === null
|
|
465
|
+
? undefined
|
|
466
|
+
: formatCapacity(metrics.memUsedBytes, metrics.memTotalBytes)}
|
|
467
|
+
/>
|
|
468
|
+
<Gauge
|
|
469
|
+
label={t('monitor.disk')}
|
|
470
|
+
value={diskPercent === null ? unknown : formatPercent(diskPercent)}
|
|
471
|
+
percent={diskPercent}
|
|
472
|
+
sub={metrics.diskUsedBytes === null || metrics.diskTotalBytes === null
|
|
473
|
+
? undefined
|
|
474
|
+
: formatCapacity(metrics.diskUsedBytes, metrics.diskTotalBytes)}
|
|
475
|
+
/>
|
|
476
|
+
</div>
|
|
477
|
+
<div className="rvs-monitor-facts">
|
|
478
|
+
<Fact label={t('monitor.temp')} value={metrics.temperatureC === null ? unknown : formatTemperature(metrics.temperatureC)} />
|
|
479
|
+
<Fact label={t('monitor.uptime')} value={metrics.uptimeSeconds === null ? unknown : formatUptime(metrics.uptimeSeconds)} />
|
|
480
|
+
<Fact label={t('monitor.load')} value={loadText} />
|
|
481
|
+
<Fact
|
|
482
|
+
label={t('monitor.net')}
|
|
483
|
+
value={netText}
|
|
484
|
+
title={metrics.netRxBps === null && metrics.netTxBps === null ? t('monitor.warming') : undefined}
|
|
485
|
+
/>
|
|
486
|
+
</div>
|
|
487
|
+
<div className="rvs-monitor-sparks">
|
|
488
|
+
<Spark label={t('monitor.cpuHistory')} values={history.cpu} tone="cpu" empty={t('monitor.warming')} />
|
|
489
|
+
<Spark label={t('monitor.memHistory')} values={history.mem} tone="mem" empty={t('monitor.warming')} />
|
|
490
|
+
<Spark label={t('monitor.netHistory')} values={history.netRx} valuesAlt={history.netTx} tone="net" empty={t('monitor.warming')} />
|
|
491
|
+
<Spark label={t('monitor.tempHistory')} values={history.temp} tone="temp" empty={t('monitor.unknown')} />
|
|
492
|
+
</div>
|
|
493
|
+
<div className="rvs-monitor-hint">
|
|
494
|
+
{metrics.kernel === null
|
|
495
|
+
? t('monitor.linuxOnly')
|
|
496
|
+
: `${metrics.kernel}${metrics.cpuModel === null ? '' : ` · ${metrics.cpuModel}`}${metrics.ip === null ? '' : ` · ${metrics.ip}`}`}
|
|
497
|
+
</div>
|
|
498
|
+
</>
|
|
499
|
+
) : (
|
|
500
|
+
<div className="rvs-monitor-hint">{metrics.reason ?? t('monitor.noData')}</div>
|
|
501
|
+
)}
|
|
502
|
+
</div>
|
|
503
|
+
)
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const renderAll = (targets: string[]): ReactNode => {
|
|
507
|
+
const okCount = targets.filter(alias => samples[alias]?.state === 'ok').length
|
|
508
|
+
return (
|
|
509
|
+
<div className="rvs-monitor-list">
|
|
510
|
+
<div className="rvs-monitor-summary">
|
|
511
|
+
{t('monitor.allSummary')
|
|
512
|
+
.replace('{ok}', String(okCount))
|
|
513
|
+
.replace('{total}', String(targets.length))}
|
|
514
|
+
</div>
|
|
515
|
+
{targets.map((alias) => {
|
|
516
|
+
const metrics = samples[alias]
|
|
517
|
+
const state: RemoteMetricsState = metrics?.state ?? 'unknown'
|
|
518
|
+
const label = stateLabel(state)
|
|
519
|
+
const cpuPercent = metrics?.cpuPercent ?? null
|
|
520
|
+
const memPercent = metrics?.memPercent ?? null
|
|
521
|
+
return (
|
|
522
|
+
<button
|
|
523
|
+
key={alias}
|
|
524
|
+
type="button"
|
|
525
|
+
className={`rvs-monitor-row ${state}`}
|
|
526
|
+
onClick={() => choose(`host:${alias}`)}
|
|
527
|
+
title={t('monitor.inspect')}
|
|
528
|
+
>
|
|
529
|
+
<span className="rvs-monitor-row-top">
|
|
530
|
+
<span className={`rvs-monitor-dot ${state}`} role="img" aria-label={label} />
|
|
531
|
+
<span className="rvs-monitor-row-name">{alias}</span>
|
|
532
|
+
<span className="rvs-monitor-row-host">{hostLabelOf(alias, props.hosts)}</span>
|
|
533
|
+
{metrics === undefined
|
|
534
|
+
? <MiniSpinner />
|
|
535
|
+
: <span className="rvs-monitor-row-cpu">{cpuPercent === null ? unknown : formatPercent(cpuPercent)}</span>}
|
|
536
|
+
</span>
|
|
537
|
+
<span className="rvs-monitor-row-bars">
|
|
538
|
+
<span
|
|
539
|
+
className="rvs-monitor-row-bar"
|
|
540
|
+
title={`${t('monitor.cpu')} ${cpuPercent === null ? unknown : formatPercent(cpuPercent)}`}
|
|
541
|
+
>
|
|
542
|
+
<span className={`rvs-monitor-bar-fill ${metricTone(cpuPercent)}`} style={{ width: `${cpuPercent === null ? 0 : Math.max(0, Math.min(100, cpuPercent))}%` }} />
|
|
543
|
+
</span>
|
|
544
|
+
<span
|
|
545
|
+
className="rvs-monitor-row-bar"
|
|
546
|
+
title={`${t('monitor.ram')} ${memPercent === null ? unknown : formatPercent(memPercent)}`}
|
|
547
|
+
>
|
|
548
|
+
<span className={`rvs-monitor-bar-fill ${metricTone(memPercent)}`} style={{ width: `${memPercent === null ? 0 : Math.max(0, Math.min(100, memPercent))}%` }} />
|
|
549
|
+
</span>
|
|
550
|
+
</span>
|
|
551
|
+
<span className="rvs-monitor-row-facts">
|
|
552
|
+
<span>{t('monitor.ram')} {memPercent === null ? unknown : formatPercent(memPercent)}</span>
|
|
553
|
+
<span>{t('monitor.temp')} {metrics?.temperatureC === null || metrics?.temperatureC === undefined ? unknown : formatTemperature(metrics.temperatureC)}</span>
|
|
554
|
+
<span>{t('monitor.uptime')} {metrics?.uptimeSeconds === null || metrics?.uptimeSeconds === undefined ? unknown : formatUptime(metrics.uptimeSeconds)}</span>
|
|
555
|
+
</span>
|
|
556
|
+
</button>
|
|
557
|
+
)
|
|
558
|
+
})}
|
|
559
|
+
<div className="rvs-monitor-hint">{t('monitor.linuxOnly')}</div>
|
|
560
|
+
</div>
|
|
561
|
+
)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const single = aliases.length === 1 ? aliases[0] : undefined
|
|
565
|
+
|
|
566
|
+
return (
|
|
567
|
+
<div className="rvs-pane grow">
|
|
568
|
+
<div className="rvs-header rvs-monitor-header">
|
|
569
|
+
<span className="rvs-title">{t('tab.monitor')}</span>
|
|
570
|
+
<select
|
|
571
|
+
className="rvs-select"
|
|
572
|
+
value={selectValue}
|
|
573
|
+
onChange={(event) => choose(event.target.value)}
|
|
574
|
+
disabled={props.hosts.length === 0}
|
|
575
|
+
title={`${t('monitor.selectScope')}${currentAlias === '' ? '' : ` · ${currentAlias}`}`}
|
|
576
|
+
style={{ flex: 1, minWidth: 90 }}
|
|
577
|
+
>
|
|
578
|
+
{/* No "(alias)" suffix: the card title already shows it, and the
|
|
579
|
+
suffix is what got ellipsised in the 230px sidebar. The current
|
|
580
|
+
host is in the select's title tooltip instead. */}
|
|
581
|
+
<option value="current" style={optionStyle}>{t('monitor.scopeCurrent')}</option>
|
|
582
|
+
{props.hosts.map(host => (
|
|
583
|
+
<option key={host.alias} value={`host:${host.alias}`} style={optionStyle}>
|
|
584
|
+
{host.alias}
|
|
585
|
+
</option>
|
|
586
|
+
))}
|
|
587
|
+
<option value="all" style={optionStyle}>{t('monitor.scopeAll')}</option>
|
|
588
|
+
</select>
|
|
589
|
+
<IconButton
|
|
590
|
+
title={t('monitor.settings')}
|
|
591
|
+
onClick={() => setSettingsOpen(open => !open)}
|
|
592
|
+
className={settingsOpen ? 'active' : undefined}
|
|
593
|
+
>
|
|
594
|
+
<IconSettings />
|
|
595
|
+
</IconButton>
|
|
596
|
+
<IconButton
|
|
597
|
+
title={paused ? t('monitor.resume') : t('monitor.pause')}
|
|
598
|
+
onClick={() => setPaused(value => !value)}
|
|
599
|
+
>
|
|
600
|
+
{paused ? <IconPlay /> : <IconPause />}
|
|
601
|
+
</IconButton>
|
|
602
|
+
<IconButton
|
|
603
|
+
title={t('monitor.refresh')}
|
|
604
|
+
onClick={refresh}
|
|
605
|
+
disabled={aliases.length === 0 || refreshing}
|
|
606
|
+
>
|
|
607
|
+
{refreshing ? <MiniSpinner /> : <IconRefresh size={14} />}
|
|
608
|
+
</IconButton>
|
|
609
|
+
</div>
|
|
610
|
+
{settingsOpen && (
|
|
611
|
+
<div className="rvs-monitor-settings">
|
|
612
|
+
<div className="rvs-monitor-settings-head">
|
|
613
|
+
<span className="rvs-monitor-settings-label">{t('monitor.interval')}</span>
|
|
614
|
+
<span className="rvs-monitor-settings-hint">{t('monitor.intervalHint')}</span>
|
|
615
|
+
</div>
|
|
616
|
+
<Segmented
|
|
617
|
+
value={String(intervalMs)}
|
|
618
|
+
onChange={chooseInterval}
|
|
619
|
+
options={[
|
|
620
|
+
{ id: '5000', label: t('monitor.interval5') },
|
|
621
|
+
{ id: '10000', label: t('monitor.interval10') },
|
|
622
|
+
{ id: '30000', label: t('monitor.interval30') },
|
|
623
|
+
]}
|
|
624
|
+
/>
|
|
625
|
+
</div>
|
|
626
|
+
)}
|
|
627
|
+
<div className="rvs-monitor-body">
|
|
628
|
+
{props.hosts.length === 0 && <div className="rvs-banner warn">{t('monitor.noHosts')}</div>}
|
|
629
|
+
{props.hosts.length > 0 && aliases.length === 0 && <div className="rvs-empty">{t('monitor.noHost')}</div>}
|
|
630
|
+
{paused && <div className="rvs-banner info">{t('monitor.paused')}</div>}
|
|
631
|
+
{single !== undefined && renderDetail(single)}
|
|
632
|
+
{single === undefined && aliases.length > 1 && renderAll(aliases)}
|
|
633
|
+
</div>
|
|
634
|
+
</div>
|
|
635
|
+
)
|
|
636
|
+
}
|
|
@@ -17,6 +17,7 @@ import { EditorPane } from './EditorPane.tsx'
|
|
|
17
17
|
import { FloatingEditorPlaceholder } from './FloatingPlaceholder.tsx'
|
|
18
18
|
import { DownloadDock } from './DownloadDock.tsx'
|
|
19
19
|
import { PortsView, IconPlug } from './PortsView.tsx'
|
|
20
|
+
import { MonitorView, IconMonitor } from './MonitorView.tsx'
|
|
20
21
|
import { QuickOpen } from './QuickOpen.tsx'
|
|
21
22
|
import { RemoteExplorer } from './RemoteExplorer.tsx'
|
|
22
23
|
import { SearchView } from './SearchView.tsx'
|
|
@@ -38,7 +39,7 @@ import {
|
|
|
38
39
|
MiniSpinner,
|
|
39
40
|
} from './vsc/kit.tsx'
|
|
40
41
|
|
|
41
|
-
type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'ports' | 'workspaces'
|
|
42
|
+
type RailView = 'explorer' | 'search' | 'scm' | 'history' | 'editor' | 'terminal' | 'ports' | 'monitor' | 'workspaces'
|
|
42
43
|
|
|
43
44
|
const SPLIT_KEY = 'dsh-remote-vs.split'
|
|
44
45
|
const HIDDEN_KEY = 'dsh-remote-vs.showHidden'
|
|
@@ -302,7 +303,7 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
|
|
|
302
303
|
// A profile with no binding has nothing to explore: the workspaces view (the
|
|
303
304
|
// wizard) takes over until one exists.
|
|
304
305
|
useEffect(() => {
|
|
305
|
-
if (store.workspaces.length === 0 && view !== 'workspaces') go('workspaces')
|
|
306
|
+
if (store.workspaces.length === 0 && view !== 'workspaces' && view !== 'monitor') go('workspaces')
|
|
306
307
|
}, [store.workspaces.length, view, go])
|
|
307
308
|
|
|
308
309
|
/**
|
|
@@ -434,6 +435,11 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
|
|
|
434
435
|
// Same shape as the terminal: its own header (host picker + refresh) and
|
|
435
436
|
// its own scroller, so no viewpad wrapper either.
|
|
436
437
|
return <PortsView t={t} hosts={store.hosts} visible={panelLive('ports')} />
|
|
438
|
+
case 'monitor':
|
|
439
|
+
// Live host metrics: own header (scope picker + refresh/pause) and its
|
|
440
|
+
// own scroller. Cross-host by design, so it reads `store.hosts` rather
|
|
441
|
+
// than the current binding.
|
|
442
|
+
return <MonitorView t={t} hosts={store.hosts} visible={panelLive('monitor')} />
|
|
437
443
|
case 'workspaces':
|
|
438
444
|
return (
|
|
439
445
|
<div className="rvs-viewpad" style={{ height: '100%' }}>
|
|
@@ -521,6 +527,7 @@ function Shell(props: { ctx: Context; visible: boolean }): ReactNode {
|
|
|
521
527
|
&& railButton('editor', store.activeTab?.rel.split('/').pop() ?? t('tab.editor'), <IconDiff size={17} />, store.tabs.length)}
|
|
522
528
|
{railButton('terminal', t('tab.terminal'), <IconTerminal size={17} />)}
|
|
523
529
|
{railButton('ports', t('tab.ports'), <IconPlug size={17} />)}
|
|
530
|
+
{railButton('monitor', t('tab.monitor'), <IconMonitor size={17} />)}
|
|
524
531
|
{railButton('workspaces', t('tab.workspaces'), <IconServer size={17} />, store.workspaces.length)}
|
|
525
532
|
</div>
|
|
526
533
|
<div className="rvs-column" ref={columnRef}>
|