dsh-server-ops-agent 0.0.0-stage → 0.3.0-beta.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/DSH-Linux-/351/246/226/346/254/241/350/277/236/346/216/245.md +33 -0
- package/LICENSE +21 -0
- package/README.md +31 -2
- package/client.js +640 -0
- package/connection-protocol.js +7 -0
- package/connections.js +213 -0
- package/cordis.patch.yml +12 -0
- package/deployment.js +93 -0
- package/generated/linux-release.json +5 -0
- package/generated/linux-release.tgz +0 -0
- package/generated/ssh-client.cjs +20120 -0
- package/generated/ssh-licenses.txt +161 -0
- package/native-workspace.js +75 -0
- package/package.json +62 -4
- package/plugin.js +140 -0
- package/ssh-client.js +182 -0
- package/workspace-tool.js +21 -0
package/client.js
ADDED
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-server-ops-agent',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const R = require('react'),
|
|
5
|
+
h = R.createElement
|
|
6
|
+
const panel = 'server-operations'
|
|
7
|
+
const Connection = R.createContext(null)
|
|
8
|
+
function useApi() {
|
|
9
|
+
const serverId = R.useContext(Connection)
|
|
10
|
+
return R.useCallback((action, data) => request(action, data, serverId), [serverId])
|
|
11
|
+
}
|
|
12
|
+
const fmt = (t) =>
|
|
13
|
+
t
|
|
14
|
+
? new Date(t * 1000).toLocaleString('zh-CN', {
|
|
15
|
+
timeZone: 'Asia/Shanghai',
|
|
16
|
+
hour12: false
|
|
17
|
+
})
|
|
18
|
+
: '未知'
|
|
19
|
+
const panelStyles = `
|
|
20
|
+
.ops-panel {
|
|
21
|
+
--canvas:#f5f7f8; --paper:#fff; --ink:#172d36; --muted:#526972; --line:#d5dfe1;
|
|
22
|
+
--accent:#006d69; --wash:#e3f2ee; --warn:#83450e; --amber:#fff0d9;
|
|
23
|
+
color-scheme:light dark; container-type:inline-size; overflow:auto; height:100%; width:100%;
|
|
24
|
+
color:var(--ink); background:var(--canvas); font:14px/1.55 "Inter","PingFang SC",system-ui,sans-serif;
|
|
25
|
+
overflow-wrap:anywhere; text-align:start;
|
|
26
|
+
}
|
|
27
|
+
.ops-panel *, .ops-panel {box-sizing:border-box}
|
|
28
|
+
.ops-inner {max-width:1120px; margin:0 auto; padding:22px clamp(14px,4cqw,36px) 48px}
|
|
29
|
+
.ops-connect {margin:0 0 16px;padding:14px;border:1px solid var(--line);border-radius:12px}
|
|
30
|
+
.ops-connect label {display:grid;gap:4px;min-width:0}
|
|
31
|
+
.ops-connect-fields {display:grid;grid-template-columns:repeat(auto-fit,minmax(min(200px,100%),1fr));gap:10px;margin:0 0 12px}
|
|
32
|
+
.ops-connect-row {display:flex;align-items:end;flex-wrap:wrap;gap:10px}
|
|
33
|
+
.ops-header {display:flex; align-items:center; gap:12px; margin:0 0 16px}
|
|
34
|
+
.ops-panel h1, .ops-panel h2, .ops-panel h3, .ops-panel p {margin:0}
|
|
35
|
+
.ops-panel h1 {font-size:23px; font-weight:720; letter-spacing:-.06em}
|
|
36
|
+
.ops-panel h2 {font-size:19px; font-weight:700; letter-spacing:-.035em; margin:24px 0 10px}
|
|
37
|
+
.ops-panel h3 {font-size:16px; font-weight:680; margin:18px 0 8px}
|
|
38
|
+
.ops-panel p {margin:8px 0}
|
|
39
|
+
.ops-panel nav {display:flex;flex-wrap:wrap;gap:4px;border-bottom:1px solid var(--line);margin:0 0 18px}
|
|
40
|
+
.ops-panel button, .ops-panel select, .ops-panel input {
|
|
41
|
+
font:inherit; font-size:13px; color:var(--ink); background:var(--paper); border:1px solid var(--line);
|
|
42
|
+
border-radius:7px; min-height:34px; padding:6px 10px; max-width:100%;
|
|
43
|
+
}
|
|
44
|
+
.ops-panel button {cursor:pointer; font-weight:580; white-space:normal}
|
|
45
|
+
.ops-panel button:hover:enabled, .ops-panel summary:hover {background-color:var(--wash)}
|
|
46
|
+
.ops-panel button:disabled, .ops-panel select:disabled {opacity:.55;cursor:default}
|
|
47
|
+
.ops-panel :is(button,summary,select,input,a):focus-visible {outline:3px solid #329b97;outline-offset:2px}
|
|
48
|
+
.ops-panel nav button {position:relative;min-width:58px;background:transparent;border:0;color:var(--muted);padding:8px 13px;border-radius:5px 5px 0 0}
|
|
49
|
+
.ops-panel nav button[aria-current] {color:var(--accent);font-weight:750}
|
|
50
|
+
.ops-panel nav button[aria-current]::after {content:"";position:absolute;bottom:-1px;left:10px;right:10px;height:3px;background:var(--accent);border-radius:3px}
|
|
51
|
+
.ops-panel .ops-primary {background:var(--accent);color:var(--paper);border-color:var(--accent)}
|
|
52
|
+
.ops-panel .ops-primary:hover:enabled {background:var(--accent);filter:brightness(.93)}
|
|
53
|
+
.ops-panel [role=status]:empty {display:none}
|
|
54
|
+
.ops-panel [role=status]:not(:empty), .ops-panel [role=alert] {padding:10px 12px;border-radius:7px;color:var(--accent);background:var(--wash)}
|
|
55
|
+
.ops-panel [role=alert] {color:var(--warn);background:var(--amber)}
|
|
56
|
+
.ops-panel time {font-variant-numeric:tabular-nums}
|
|
57
|
+
.ops-card {background:var(--paper);border:1px solid var(--line);border-radius:10px}
|
|
58
|
+
.ops-card {padding:13px 15px;margin:8px 0}
|
|
59
|
+
.ops-card h3:first-child {margin-top:0}
|
|
60
|
+
.ops-badge {display:inline-flex;align-items:center;gap:5px;white-space:nowrap;vertical-align:middle;font-size:11px;font-weight:650;padding:2px 7px;border-radius:5px}
|
|
61
|
+
.ops-badge::before {content:"";width:5px;height:5px;border-radius:50%;background:currentColor}
|
|
62
|
+
.ops-badge.ok {background:var(--wash);color:var(--accent)}
|
|
63
|
+
.ops-badge.warn {background:var(--amber);color:var(--warn)}
|
|
64
|
+
.ops-panel details.ops-disclosure {background:var(--paper);border:1px solid var(--line);border-radius:9px;margin:7px 0;padding:0 14px}
|
|
65
|
+
.ops-panel label {display:block;margin:8px 0;font-size:13px;color:var(--muted)}
|
|
66
|
+
.ops-panel label select {margin:0 0 0 6px}
|
|
67
|
+
.ops-panel .ops-fact {display:grid;grid-template-columns:minmax(64px,24%) minmax(0,1fr);gap:9px;font-size:13px}
|
|
68
|
+
.ops-fact strong {color:var(--muted);font-weight:550}
|
|
69
|
+
.ops-panel details {background:var(--paper);border-bottom:1px solid var(--line);padding:0 10px}
|
|
70
|
+
.ops-panel summary {padding:9px 0;cursor:pointer;font-size:13px}
|
|
71
|
+
.ops-panel pre {overflow:auto;max-height:320px;white-space:pre-wrap;overflow-wrap:anywhere;padding:10px;border-radius:6px;background:var(--canvas);font:12px/1.5 "IBM Plex Mono",ui-monospace,monospace;color:var(--muted)}
|
|
72
|
+
.ops-panel small {color:var(--muted)}
|
|
73
|
+
@container (max-width:390px) {
|
|
74
|
+
.ops-inner {padding-inline:12px}
|
|
75
|
+
.ops-panel label select {display:block;width:100%;margin:3px 0 0}
|
|
76
|
+
.ops-panel nav {gap:0}
|
|
77
|
+
}
|
|
78
|
+
@media (prefers-color-scheme:dark) {
|
|
79
|
+
.ops-panel {--canvas:#172327;--paper:#1e2e33;--ink:#e6efef;--muted:#adc1c7;--line:#3d5157;--accent:#8cddd0;--wash:#284641;--warn:#f5c484;--amber:#483a26}
|
|
80
|
+
.ops-panel .ops-primary {color:#10312f}
|
|
81
|
+
}
|
|
82
|
+
.ops-studio {--night:#16383c;--mint:#9fe8ca;display:grid;gap:20px}
|
|
83
|
+
.ops-panel .ops-session-row {display:block;width:100%;text-align:start;padding:12px 14px;margin-top:8px}
|
|
84
|
+
.studio-work {display:grid;grid-template-columns:minmax(0,1fr) 280px;align-items:start;gap:16px}
|
|
85
|
+
.studio-card {min-width:0;padding:20px;border:1px solid var(--line);border-radius:14px;background:var(--paper)}
|
|
86
|
+
.ops-studio h3 {margin:0;font-size:17px;line-height:1.45;letter-spacing:-.02em}
|
|
87
|
+
.studio-card-head, .studio-actions {display:flex;gap:10px;align-items:center;flex-wrap:wrap}
|
|
88
|
+
.studio-card-head, .studio-actions {justify-content:space-between}
|
|
89
|
+
.ops-studio label {margin:0}
|
|
90
|
+
.ops-studio .studio-host {display:flex;align-items:center;gap:6px;color:var(--muted)}
|
|
91
|
+
.ops-studio .studio-host select {width:auto;margin:0;font:600 13px ui-monospace,monospace}
|
|
92
|
+
.ops-studio textarea {width:100%;display:block;margin:14px 0 8px;padding:12px 14px;resize:vertical;min-height:78px;border:1px solid var(--line);border-radius:9px;background:var(--canvas);color:var(--ink);font:inherit}
|
|
93
|
+
.ops-studio textarea::placeholder {color:var(--muted)}
|
|
94
|
+
.ops-studio textarea:focus-visible {outline:2px solid var(--accent);outline-offset:2px}
|
|
95
|
+
.studio-actions {margin-top:12px}
|
|
96
|
+
.studio-actions small {font:12px/1.5 ui-monospace,"PingFang SC",monospace;color:var(--muted)}
|
|
97
|
+
.ops-studio .ops-primary {border-radius:8px;padding:8px 16px}
|
|
98
|
+
.ops-studio .ops-primary:disabled {background:var(--canvas);color:var(--muted);border-color:var(--line);opacity:1}
|
|
99
|
+
.studio-model {border-top:3px solid var(--accent);padding-top:17px}
|
|
100
|
+
.studio-model-name {display:block;font:600 18px/1.4 ui-monospace,monospace;margin:12px 0 4px;overflow-wrap:anywhere}
|
|
101
|
+
.ops-studio .studio-model-meta {margin:0 0 14px;color:var(--muted);font-size:12px}
|
|
102
|
+
.ops-studio details {border:0;padding:0;background:transparent}
|
|
103
|
+
.ops-studio summary {border-radius:5px;color:var(--accent);font-weight:600}
|
|
104
|
+
.ops-studio .studio-settings {border-top:1px solid var(--line)}
|
|
105
|
+
.studio-settings label {display:grid;gap:4px}
|
|
106
|
+
.ops-studio .studio-settings select {display:block;margin:0;width:100%}
|
|
107
|
+
.studio-settings-body {display:grid;gap:10px}
|
|
108
|
+
.studio-settings-body p {font-size:12px;color:var(--muted)}
|
|
109
|
+
.studio-settings-buttons {display:flex;gap:6px;flex-wrap:wrap}
|
|
110
|
+
.ops-studio .studio-draft {color:var(--warn);background:var(--amber);margin:0;padding:6px 8px;border-radius:5px}
|
|
111
|
+
@container (max-width:800px) {
|
|
112
|
+
.studio-work {grid-template-columns:minmax(0,1fr)}
|
|
113
|
+
.studio-model {padding:14px 18px;border-top:1px solid var(--line);border-left:3px solid var(--accent)}
|
|
114
|
+
.studio-model-name {margin:4px 0;font-size:16px}
|
|
115
|
+
}
|
|
116
|
+
@container (max-width:520px) {
|
|
117
|
+
.ops-studio {gap:14px}
|
|
118
|
+
.studio-work {gap:10px}
|
|
119
|
+
.studio-card {padding:14px}
|
|
120
|
+
.ops-studio :is(button,select,summary) {min-height:44px}
|
|
121
|
+
}
|
|
122
|
+
.server-chart {margin-bottom:22px;padding:clamp(14px,3cqw,24px);background:var(--paper);border:1px solid var(--line);border-radius:14px;font-variant-numeric:tabular-nums}
|
|
123
|
+
.server-chart header, .server-line {display:flex;justify-content:space-between;align-items:baseline;gap:8px}
|
|
124
|
+
.server-chart header {border-bottom:1px solid var(--line);padding-bottom:14px;flex-wrap:wrap}
|
|
125
|
+
.ops-panel .server-chart h2 {margin:0;font-size:22px}
|
|
126
|
+
.server-chart header b {font:600 13px ui-monospace,monospace;color:var(--muted)}
|
|
127
|
+
.server-stamp {text-align:end;display:grid;font-size:13px}
|
|
128
|
+
.server-resources {display:grid;grid-template-columns:minmax(0,1.5fr) minmax(0,1fr);gap:clamp(14px,4cqw,36px)}
|
|
129
|
+
.server-chart h3 {margin:16px 0 9px}
|
|
130
|
+
.server-meter {margin:10px 0 13px}
|
|
131
|
+
.server-line, .server-load b {font-size:13px}
|
|
132
|
+
.server-line strong {font-size:16px}
|
|
133
|
+
.server-track {position:relative;height:8px;margin:4px 0;border-radius:8px;background:var(--line)}
|
|
134
|
+
.server-track i {display:block;height:100%;background:var(--accent);border-radius:inherit}
|
|
135
|
+
.server-track.high i {background:#c67927}
|
|
136
|
+
.server-track em {position:absolute;top:-2px;bottom:-2px;border-left:2px solid var(--ink)}
|
|
137
|
+
.server-load {margin-top:12px;display:grid}
|
|
138
|
+
.server-load strong {font-size:23px}
|
|
139
|
+
.capacity-trend {border-top:1px solid var(--line);padding:14px 0 18px}
|
|
140
|
+
.trend-heading {display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap}
|
|
141
|
+
.server-chart .trend-heading h3 {margin:0;font-size:16px}
|
|
142
|
+
.trend-tabs {display:flex;flex-wrap:wrap;gap:2px;background:var(--canvas);padding:3px;border-radius:7px}
|
|
143
|
+
.trend-options {display:flex;flex-wrap:wrap;align-items:center;gap:6px}
|
|
144
|
+
.ops-panel .server-chart .trend-tabs button {margin:0;text-decoration:none;padding:4px 9px;color:var(--muted)}
|
|
145
|
+
.ops-panel .server-chart .trend-tabs button[aria-pressed=true] {background:var(--paper);color:var(--accent);box-shadow:0 1px 3px #0002}
|
|
146
|
+
.trend-meta, .trend-foot {font-size:12px;color:var(--muted)}
|
|
147
|
+
.trend-plot {display:grid;grid-template-columns:max-content minmax(0,1fr);gap:6px 9px;margin-top:16px}
|
|
148
|
+
.trend-axis {display:flex;flex-direction:column;justify-content:space-between;text-align:right;color:var(--muted);font-size:11px;line-height:1}
|
|
149
|
+
.trend-canvas {display:block;width:100%;height:110px;overflow:visible}
|
|
150
|
+
.trend-times {grid-column:2;display:flex;justify-content:space-between;color:var(--muted);font-size:11px}
|
|
151
|
+
.trend-legend {display:inline-block;width:16px;vertical-align:middle;margin:0 4px 0 8px;border-top:2px dashed #ae650a}
|
|
152
|
+
.trend-gap {display:inline-block;width:12px;height:10px;vertical-align:middle;background:var(--line);margin:0 4px 0 8px}
|
|
153
|
+
.server-alert {background:var(--amber);color:var(--warn)}
|
|
154
|
+
.server-alert {padding:6px 10px;border-radius:6px}
|
|
155
|
+
.ops-panel .server-chart button {min-height:24px;padding:0 4px;margin-left:5px;color:var(--accent);font-size:12px;border:0;background:none;text-decoration:underline}
|
|
156
|
+
@container (max-width:520px) {
|
|
157
|
+
.server-resources {grid-template-columns:minmax(0,1fr);gap:0}
|
|
158
|
+
.server-stamp {text-align:start}
|
|
159
|
+
}
|
|
160
|
+
.brief-section {padding:18px 0 5px}
|
|
161
|
+
.ops-panel .brief-section h3 {font-size:14px;line-height:1.6;margin:0 0 8px}
|
|
162
|
+
.brief-section .ops-fact {grid-template-columns:70px minmax(0,1fr)}
|
|
163
|
+
@container (max-width:520px) {
|
|
164
|
+
.brief-section {padding-top:14px}
|
|
165
|
+
}
|
|
166
|
+
`
|
|
167
|
+
const btn = (s, f, disabled = false, kind = '') =>
|
|
168
|
+
h('button', { type: 'button', onClick: f, disabled, className: kind }, s)
|
|
169
|
+
const fact = (label, value) =>
|
|
170
|
+
h('p', { className: 'ops-fact' }, h('strong', null, label), h('span', null, value))
|
|
171
|
+
const json = (v) =>
|
|
172
|
+
h('pre', null, typeof v === 'string' ? v : JSON.stringify(v, null, 2))
|
|
173
|
+
const shortTime = (ts) => new Date(ts * 1000).toLocaleTimeString('zh-CN', {
|
|
174
|
+
timeZone: 'Asia/Shanghai', hour12: false
|
|
175
|
+
})
|
|
176
|
+
const trendLabels = {pct:'已用比例',bytes:'可用空间',memory:'可用内存',load:'15 分钟平均负载'}
|
|
177
|
+
function ResourceTrend({host, resource, title, interval, threshold, hours, setHours, system=false}) {
|
|
178
|
+
const api = useApi()
|
|
179
|
+
const [history, setHistory] = R.useState(null)
|
|
180
|
+
const [error, setError] = R.useState('')
|
|
181
|
+
const [metric, setMetric] = R.useState(system?'memory':'pct')
|
|
182
|
+
R.useEffect(()=>{
|
|
183
|
+
let live=true, timer
|
|
184
|
+
async function refresh() {
|
|
185
|
+
try {
|
|
186
|
+
const data=await api('overview',{section:'resource-history',host,resource})
|
|
187
|
+
if (!Array.isArray(data.rows) || !Number.isFinite(data.end)) throw Error('后台尚未提供资源历史')
|
|
188
|
+
if (live) {setHistory(data);setError('')}
|
|
189
|
+
} catch (e) {if (live) setError(e.message)}
|
|
190
|
+
if (live) timer=setTimeout(refresh,interval*1000)
|
|
191
|
+
}
|
|
192
|
+
refresh()
|
|
193
|
+
return ()=>{live=false;clearTimeout(timer)}
|
|
194
|
+
},[host,resource,interval])
|
|
195
|
+
const pct=metric==='pct' || metric==='memory'
|
|
196
|
+
const label=trendLabels[metric]
|
|
197
|
+
const heading=h('div',{className:'trend-heading'},h('h3',null,title+' · 最近 '+hours+' 小时'),
|
|
198
|
+
h('div',{className:'trend-options'},
|
|
199
|
+
h('div',{className:'trend-tabs',role:'group','aria-label':'指标'},(system?['memory','load']:['pct','bytes']).map(key=>
|
|
200
|
+
h('button',{key,type:'button','aria-pressed':metric===key,onClick:()=>setMetric(key)},trendLabels[key]))),
|
|
201
|
+
h('select',{'aria-label':'历史时段',value:hours,onChange:e=>setHours(Number(e.target.value))},
|
|
202
|
+
[1,6,24].map(n=>h('option',{key:n,value:n},n+' 小时')))))
|
|
203
|
+
const section=(...children)=>h('section',{className:'capacity-trend','aria-label':title+'趋势'},
|
|
204
|
+
heading,error && h('p',{role:'alert'},'趋势更新失败 · '+error),...children)
|
|
205
|
+
if (!history) return section(!error && h('p',null,'正在读取资源历史…'))
|
|
206
|
+
const end=history.end, start=end-hours*3600
|
|
207
|
+
const rows=history.rows.filter(row=>row.ts>=start && row.ts<=end)
|
|
208
|
+
const runs=[]
|
|
209
|
+
let run=null, low=Infinity, high=-Infinity, count=0
|
|
210
|
+
for (const row of rows) {
|
|
211
|
+
const value=row[metric]
|
|
212
|
+
if (!['ok','bad'].includes(row.state) || !Number.isFinite(value) || value<0 || (pct && value>100)) {
|
|
213
|
+
run=null
|
|
214
|
+
continue
|
|
215
|
+
}
|
|
216
|
+
if (!run || row.ts-run.at(-1).ts>2*interval+5) {run=[];runs.push(run)}
|
|
217
|
+
const v=metric==='bytes' ? value/2**30 : value
|
|
218
|
+
run.push({ts:row.ts,v})
|
|
219
|
+
low=Math.min(low,v);high=Math.max(high,v);count++
|
|
220
|
+
}
|
|
221
|
+
const windowText=fmt(start)+' 至 '+fmt(end)+'(北京时间)'
|
|
222
|
+
if (!count) return section(h('small',null,windowText),h('p',null,'这段时间没有有效的'+label+'采样。'))
|
|
223
|
+
const mark=metric==='pct' && Number.isFinite(threshold) && threshold>=0 && threshold<=100 ? threshold : null
|
|
224
|
+
const span=Math.max(high-low,pct?2:0.02)
|
|
225
|
+
const floor=Math.max(0,Math.min(low,mark ?? low)-span/2)
|
|
226
|
+
const ceil=pct ? Math.min(100,Math.max(high,mark ?? high)+span/2) : high+span/2
|
|
227
|
+
const x=t=>100*(t-start)/(end-start)
|
|
228
|
+
const y=v=>100*(ceil-v)/(ceil-floor)
|
|
229
|
+
const format=v=>pct ? Number(v.toFixed(1))+'%' : metric==='bytes' ? v.toFixed(3)+' GiB' : v.toFixed(2)
|
|
230
|
+
const time=t=>shortTime(t).slice(0,5)
|
|
231
|
+
const strokes={vectorEffect:'non-scaling-stroke',fill:'none'}
|
|
232
|
+
const gaps=[]
|
|
233
|
+
let previous=start
|
|
234
|
+
for (const [i,points] of runs.entries()) {
|
|
235
|
+
const first=points[0].ts
|
|
236
|
+
if (first>previous && (i>0 || first-start>interval || rows[0].ts<first))
|
|
237
|
+
gaps.push([previous,first])
|
|
238
|
+
previous=points.at(-1).ts
|
|
239
|
+
}
|
|
240
|
+
if (end-previous>interval || rows.at(-1).ts>previous) gaps.push([previous,end])
|
|
241
|
+
const summary=low===high ? '有效采样均为 '+format(low) : '有效采样范围 '+format(low)+' – '+format(high)
|
|
242
|
+
return section(h('p',{className:'trend-meta'},windowText),
|
|
243
|
+
h('div',{className:'trend-plot'},
|
|
244
|
+
h('div',{className:'trend-axis'},h('span',null,format(ceil)),h('span',null,format((ceil+floor)/2)),h('span',null,format(floor))),
|
|
245
|
+
h('svg',{className:'trend-canvas',viewBox:'0 0 100 100',preserveAspectRatio:'none',role:'img','aria-label':label+'趋势,'+summary},
|
|
246
|
+
gaps.map(([a,b])=>h('rect',{key:a,x:x(a),y:0,width:x(b)-x(a),height:100,fill:'var(--line)',opacity:0.65})),
|
|
247
|
+
[0,50,100].map(v=>h('line',{key:v,x1:0,x2:100,y1:v,y2:v,stroke:'var(--line)',...strokes})),
|
|
248
|
+
runs.map((points,i)=>h('path',{key:i,d:points.map((p,j)=>(j?'L':'M')+x(p.ts).toFixed(3)+' '+y(p.v).toFixed(3)).join(' ')+(points.length===1?' l0 0.01':''),
|
|
249
|
+
stroke:'var(--accent)',strokeWidth:3,strokeLinecap:'round',...strokes})),
|
|
250
|
+
mark!==null && h('line',{x1:0,x2:100,y1:y(mark),y2:y(mark),stroke:'#ae650a',strokeDasharray:'5 5',strokeWidth:1.4,...strokes})),
|
|
251
|
+
h('div',{className:'trend-times'},[0,1,2,3,4].map(i=>h('span',{key:i},time(start+i*(end-start)/4))))),
|
|
252
|
+
h('p',{className:'trend-foot'},summary+' · '+count+' 次',
|
|
253
|
+
mark!==null && h(R.Fragment,null,h('i',{className:'trend-legend'}),'当前告警线 '+mark+'%'),
|
|
254
|
+
gaps.length>0 && h(R.Fragment,null,h('i',{className:'trend-gap'}),'缺测时段')))
|
|
255
|
+
}
|
|
256
|
+
const labels = {ok:'正常',bad:'异常',unknown:'缺测或待核实'}
|
|
257
|
+
function ServerStatus({host, samples, clock, interval, disconnected, openEvent, service}) {
|
|
258
|
+
const [hours,setHours]=R.useState(24)
|
|
259
|
+
const sample = name => samples.find(s => s.signal === name)
|
|
260
|
+
const ssh = sample('本机 SSH 服务')
|
|
261
|
+
const fresh = s => s && Number.isFinite(s.ts) && clock - s.ts <= 2 * interval + 5 && !disconnected
|
|
262
|
+
const connected = !disconnected && fresh(sample('本机采集')) && sample('本机采集').state === 'ok'
|
|
263
|
+
const current = s => connected && fresh(s) && s.state !== 'unknown'
|
|
264
|
+
const capacity = sample('主机容量')
|
|
265
|
+
const mounts = samples.filter(s => s.signal.startsWith('挂载容量 '))
|
|
266
|
+
.sort((a,b) => (b.value?.used_pct ?? -1) - (a.value?.used_pct ?? -1))
|
|
267
|
+
const connection = disconnected ? '同步中断' : '已从服务器同步'
|
|
268
|
+
const percent = n => Number.isFinite(n) && n >= 0 && n <= 100
|
|
269
|
+
function meter(label, s, value, note, threshold) {
|
|
270
|
+
const valid = current(s) && percent(value)
|
|
271
|
+
const warning = valid && percent(threshold) && value >= threshold
|
|
272
|
+
return h('div',{className:'server-meter',key:label},
|
|
273
|
+
h('div',{className:'server-line'},h('b',null,label),h('strong',null,valid ? value+'%' : '缺测')),
|
|
274
|
+
h('div',{className:'server-track'+(warning?' high':''),'aria-hidden':true},
|
|
275
|
+
valid && h('i',{style:{width:value+'%'}}),
|
|
276
|
+
valid && percent(threshold) && h('em',{style:{left:threshold+'%'}})),
|
|
277
|
+
valid && h('small',null,note,percent(threshold) ? ' · 告警线 '+threshold+'%' : '',
|
|
278
|
+
warning && s.incident && h('button',{type:'button',onClick:()=>openEvent(s.incident)},'查看容量告警')))
|
|
279
|
+
}
|
|
280
|
+
const memory = capacity?.value?.available_memory_pct
|
|
281
|
+
const load = capacity?.value?.load15
|
|
282
|
+
const failure = sample('失败单元')
|
|
283
|
+
const space = s => Number.isFinite(s?.value?.available_bytes) ?
|
|
284
|
+
'可用 '+(s.value.available_bytes / 2**30).toLocaleString('zh-CN',{maximumFractionDigits:2})+' GiB' : '可用空间未知'
|
|
285
|
+
return h('section',{className:'server-chart','aria-label':host+' 服务器现状'},
|
|
286
|
+
h('header',null,h('div',null,h('h2',null,'服务器现状'),h('b',null,host)),
|
|
287
|
+
h('div',{className:'server-stamp'},h('strong',null,connection),
|
|
288
|
+
h('small',null,'服务版本 '+service.version+' · 最近同步 '+fmt(service.lastSyncedAt)),
|
|
289
|
+
h('small',null,'最近服务器采样 · '+fmt(service.latestSample)),
|
|
290
|
+
h('small',null,'DSH 最近 SSH 连接 · '+fmt(service.lastConnectedAt)),
|
|
291
|
+
ssh && h('small',null,'本机 SSH 服务 · '+labels[ssh.state]+' · '+fmt(ssh.ts)))),
|
|
292
|
+
h('div',{className:'server-resources'},
|
|
293
|
+
h('section',null,h('h3',null,'磁盘已用'),
|
|
294
|
+
...mounts.map(s=>meter(s.signal.slice(5),s,s.value?.used_pct,space(s),s.value?.threshold_pct)),
|
|
295
|
+
meter('/(根分区)',capacity,capacity?.value?.root_used_pct,space(capacity))),
|
|
296
|
+
h('section',null,h('h3',null,'宿主机内存与负载'),
|
|
297
|
+
meter('可用内存',capacity,memory,'可供应用使用'),
|
|
298
|
+
h('div',{className:'server-load'},h('b',null,'15 分钟平均负载'),
|
|
299
|
+
h('strong',null,current(capacity) && Number.isFinite(load) ? load.toFixed(2) : '缺测'),
|
|
300
|
+
current(capacity) && Number.isFinite(capacity.value?.logical_cpu) &&
|
|
301
|
+
h('small',null,capacity.value.logical_cpu+' 个逻辑 CPU')))),
|
|
302
|
+
h(ResourceTrend,{host,interval,hours,setHours,resource:'/',title:'宿主机内存与负载',system:true}),
|
|
303
|
+
current(failure) && failure.state === 'bad' && h('p',{className:'server-alert'},
|
|
304
|
+
'系统服务异常 · '+(failure.value?.units?.join('、') || '检测到失败单元'),
|
|
305
|
+
failure.incident && btn('查看事件',()=>openEvent(failure.incident))))
|
|
306
|
+
}
|
|
307
|
+
async function request(action, data = {}, serverId) {
|
|
308
|
+
const res = await fetch('/server-operations/api', {
|
|
309
|
+
method: 'POST',
|
|
310
|
+
cache: 'no-store',
|
|
311
|
+
...(action==='overview' && !data.section ? {signal:AbortSignal.timeout(32_000)} : {}),
|
|
312
|
+
headers: {
|
|
313
|
+
'content-type': 'application/json',
|
|
314
|
+
'x-server-ops': window.location.protocol === 'dsh-app:' && window.location.hostname === 'app'
|
|
315
|
+
? 'desktop' : '1'
|
|
316
|
+
},
|
|
317
|
+
body: JSON.stringify({ action, data, serverId })
|
|
318
|
+
})
|
|
319
|
+
const r = await res.json().catch(() => ({}))
|
|
320
|
+
if (!res.ok) throw Error(r.error || '读取工作台接口失败(HTTP ' + res.status + ')')
|
|
321
|
+
return r
|
|
322
|
+
}
|
|
323
|
+
let client
|
|
324
|
+
function OperatorPage({hosts}) {
|
|
325
|
+
const [chosen, setChosen] = R.useState('')
|
|
326
|
+
const host = hosts.includes(chosen) ? chosen : hosts[0] || ''
|
|
327
|
+
return h(WorkspaceChats,{key:host,host,hosts,setChosen})
|
|
328
|
+
}
|
|
329
|
+
// A blank native chat is absent from the conversation list until its first message.
|
|
330
|
+
const unfinishedChats=new Map()
|
|
331
|
+
function WorkspaceChats({host,hosts,setChosen}) {
|
|
332
|
+
const api = useApi()
|
|
333
|
+
const [workspace,setWorkspace]=R.useState(null)
|
|
334
|
+
const [revision,refresh]=R.useState(0)
|
|
335
|
+
const sessions=R.useSyncExternalStore(fn=>client.sessions.list.subscribe(fn),()=>client.sessions.list.getSnapshot())
|
|
336
|
+
const spaces=R.useSyncExternalStore(fn=>client.workspaces.list.subscribe(fn),()=>client.workspaces.list.getSnapshot())
|
|
337
|
+
const [catalog, setCatalog] = R.useState(null)
|
|
338
|
+
const [catalogError,setCatalogError]=R.useState('')
|
|
339
|
+
const [draft, setDraft] = R.useState({provider:'',model:''})
|
|
340
|
+
const [workspaceError,setWorkspaceError]=R.useState('')
|
|
341
|
+
const [actionError,setActionError]=R.useState(null)
|
|
342
|
+
const [pending,setPending]=R.useState(false)
|
|
343
|
+
const lock=R.useRef(false)
|
|
344
|
+
const visible=R.useRef(false)
|
|
345
|
+
R.useEffect(()=>{
|
|
346
|
+
visible.current=true
|
|
347
|
+
return ()=>{visible.current=false}
|
|
348
|
+
},[])
|
|
349
|
+
const catalogRequest=R.useRef(0)
|
|
350
|
+
const loadCatalog = async () => {
|
|
351
|
+
const request=++catalogRequest.current
|
|
352
|
+
try {
|
|
353
|
+
const c = await api('agent-models')
|
|
354
|
+
if(request!==catalogRequest.current)return
|
|
355
|
+
setCatalog(c)
|
|
356
|
+
setDraft(c.selection || {provider:'',model:''})
|
|
357
|
+
setCatalogError('')
|
|
358
|
+
} catch(e) {
|
|
359
|
+
if(request===catalogRequest.current)setCatalogError(e.message)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
R.useEffect(()=>{loadCatalog()},[])
|
|
363
|
+
R.useEffect(()=>{
|
|
364
|
+
if (!host) return
|
|
365
|
+
let live=true, timer
|
|
366
|
+
async function load() {
|
|
367
|
+
try {
|
|
368
|
+
const result=await api('agent-workspace',{host})
|
|
369
|
+
await client.sessions.refresh()
|
|
370
|
+
if(live) {
|
|
371
|
+
setWorkspace(result);setWorkspaceError('')
|
|
372
|
+
if(result.pendingImport) timer=setTimeout(load,4000)
|
|
373
|
+
}
|
|
374
|
+
} catch(e) {if(live) setWorkspaceError(e.message)}
|
|
375
|
+
}
|
|
376
|
+
load()
|
|
377
|
+
return ()=>{live=false;clearTimeout(timer)}
|
|
378
|
+
},[host,revision])
|
|
379
|
+
async function act(work) {
|
|
380
|
+
if (lock.current) return
|
|
381
|
+
lock.current=true;setPending(true);setActionError(null)
|
|
382
|
+
try { await work() } catch(e) { setActionError({message:e.message,retry:work}) }
|
|
383
|
+
finally { lock.current=false;setPending(false) }
|
|
384
|
+
}
|
|
385
|
+
async function newChat() {
|
|
386
|
+
const {workspaceId}=workspace
|
|
387
|
+
let chat=unfinishedChats.get(workspaceId)
|
|
388
|
+
if (!chat) {
|
|
389
|
+
chat={id:null,ready:null}
|
|
390
|
+
unfinishedChats.set(workspaceId,chat)
|
|
391
|
+
}
|
|
392
|
+
// Share preparation if the workspace is reopened while the request is pending.
|
|
393
|
+
chat.ready ??= (async()=>{
|
|
394
|
+
chat.id ??= await client.sessions.create({workspaceId,agentPreset:'server-ops-chat'})
|
|
395
|
+
await api('agent-workspace-model',{host,session:chat.id})
|
|
396
|
+
})().catch(e=>{
|
|
397
|
+
chat.ready=null
|
|
398
|
+
if (!chat.id) unfinishedChats.delete(workspaceId)
|
|
399
|
+
throw e
|
|
400
|
+
})
|
|
401
|
+
await chat.ready
|
|
402
|
+
if (!visible.current) return
|
|
403
|
+
await client.uiWorkspace.openSession(chat.id)
|
|
404
|
+
unfinishedChats.delete(workspaceId)
|
|
405
|
+
}
|
|
406
|
+
const provider=catalog?.providers.find(p=>p.id===draft.provider)
|
|
407
|
+
const active=catalog?.selection || catalog?.default
|
|
408
|
+
const dirty=(catalog?.selection?.provider || '')!==draft.provider ||
|
|
409
|
+
(catalog?.selection?.model || '')!==draft.model
|
|
410
|
+
const space=spaces.items.find(item=>item.workspaceId===workspace?.workspaceId)
|
|
411
|
+
const chats=(space?.sessionIds || []).filter(id=>!spaces.archivedSessionIds.includes(id))
|
|
412
|
+
.map(id=>sessions.byId[id]).filter(s=>s && !s.blank && s.projectionValues?.agentPreset==='server-ops-chat')
|
|
413
|
+
.sort((a,b)=>b.updatedAt-a.updatedAt)
|
|
414
|
+
const control = (label, fn, disabled = false, primary = false) =>
|
|
415
|
+
h('button', {type:'button', disabled:pending || disabled,
|
|
416
|
+
className:primary ? 'ops-primary' : '', onClick:()=>act(fn)}, label)
|
|
417
|
+
const activeProvider = catalog?.providers.find(p=>p.id===active?.provider)
|
|
418
|
+
const validDraft = !draft.provider || provider?.models.some(m=>m.id===draft.model)
|
|
419
|
+
return h('section',{className:'ops-studio'},
|
|
420
|
+
h('div',{className:'studio-work'},
|
|
421
|
+
h('section',{className:'studio-card'},
|
|
422
|
+
h('div',{className:'studio-card-head'},h('h3',null,'运维会话'),
|
|
423
|
+
h('label',{className:'studio-host'},'主机',h('select',{value:host,disabled:pending || !host,
|
|
424
|
+
onChange:e=>setChosen(e.target.value)},...hosts.map(id=>h('option',{key:id,value:id},id))))),
|
|
425
|
+
h('div',{className:'studio-actions'},control(unfinishedChats.has(workspace?.workspaceId)?'继续打开运维会话':'新建运维会话',newChat,!workspace,true)),
|
|
426
|
+
h('p',null,'发出第一条消息后,可以从左侧工作区继续这次对话。'),
|
|
427
|
+
!workspace && !workspaceError && h('p',null,host ? '正在读取工作区…' : '尚无已登记的主机。'),
|
|
428
|
+
workspace?.pending?.map((row,i)=>h('p',{key:i},row.status+' · '+row.question)),
|
|
429
|
+
workspace && h('h3',null,'继续会话'),
|
|
430
|
+
workspace && !chats.length && h('p',null,'还没有已发送消息的会话。'),
|
|
431
|
+
...chats.map(s=>h('button',{key:s.id,type:'button',className:'ops-session-row',
|
|
432
|
+
onClick:()=>client.uiWorkspace.openSession(s.id)},s.displayTitle))),
|
|
433
|
+
h('aside',{className:'studio-card studio-model','aria-label':'调查模型'},
|
|
434
|
+
h('div',{className:'studio-card-head'},h('h3',null,'调查模型'),active && h('span',{className:'ops-badge ok'},catalogError?'上次读取':'当前生效')),
|
|
435
|
+
catalogError && h('p',{role:'alert'},catalogError,' ',control('重试读取模型配置',loadCatalog)),
|
|
436
|
+
h('strong',{className:'studio-model-name'},active?.model || '尚未读取'),
|
|
437
|
+
h('p',{className:'studio-model-meta'},active && (activeProvider?.name || active.provider),
|
|
438
|
+
active && (' · '+(catalog.selection ? '运维专用' : '跟随桌面默认'))),
|
|
439
|
+
h('details',{className:'studio-settings'},h('summary',null,'切换模型',dirty && ' · 未保存'),
|
|
440
|
+
h('div',{className:'studio-settings-body'},
|
|
441
|
+
catalog && h('label',null,'供应商',h('select',{value:draft.provider,disabled:pending,onChange:e=>{
|
|
442
|
+
const p=catalog.providers.find(p=>p.id===e.target.value)
|
|
443
|
+
setDraft({provider:p?.id || '',model:p?.models[0]?.id || ''})
|
|
444
|
+
}},h('option',{value:''},'跟随 DSH 桌面默认'),...catalog.providers.map(p=>h('option',{key:p.id,value:p.id},p.name)))),
|
|
445
|
+
draft.provider && h('label',null,'模型',h('select',{value:draft.model,disabled:pending,
|
|
446
|
+
onChange:e=>setDraft({...draft,model:e.target.value})},
|
|
447
|
+
...(provider?.models || []).map(m=>h('option',{key:m.id,value:m.id},m.id)))),
|
|
448
|
+
dirty && h('p',{className:'studio-draft'},'待应用 · '+(draft.provider ? draft.model : '跟随桌面默认')),
|
|
449
|
+
h('div',{className:'studio-settings-buttons'},
|
|
450
|
+
dirty && control('保存并应用',async()=>{
|
|
451
|
+
await api('agent-model',{selection:draft.provider ? draft : null})
|
|
452
|
+
await loadCatalog()
|
|
453
|
+
},!validDraft,true),
|
|
454
|
+
dirty && control('撤销选择',()=>setDraft(catalog.selection || {provider:'',model:''})),
|
|
455
|
+
!dirty && control('重新读取 DSH 配置',loadCatalog)),
|
|
456
|
+
h('p',null,'保存后用于下一次本机主动排查和告警调查。'))))),
|
|
457
|
+
workspaceError && h('p',{role:'alert'},workspaceError,' ',control('重新读取工作区',()=>refresh(v=>v+1))),
|
|
458
|
+
actionError && h('p',{role:'alert'},actionError.message,' ',control('重试',actionError.retry)))
|
|
459
|
+
}
|
|
460
|
+
function Page() {
|
|
461
|
+
const [connection,setConnection] = R.useState(null)
|
|
462
|
+
const [adding,setAdding] = R.useState(false)
|
|
463
|
+
const [busy,setBusy] = R.useState(false)
|
|
464
|
+
const [error,setError] = R.useState('')
|
|
465
|
+
const [offer,setOffer] = R.useState(null)
|
|
466
|
+
const [fields,setFields] = R.useState({host:'',port:'22',user:'',fingerprint:'',keyPath:''})
|
|
467
|
+
const refresh = () => request('connection-status').then(value => {
|
|
468
|
+
setConnection(value)
|
|
469
|
+
setError('')
|
|
470
|
+
}, error => setError(error.message))
|
|
471
|
+
R.useEffect(() => { refresh() }, [])
|
|
472
|
+
async function connect(action, data) {
|
|
473
|
+
setBusy(true)
|
|
474
|
+
setError('')
|
|
475
|
+
try {
|
|
476
|
+
if (action === 'connection-add' || action === 'connection-select') setOffer(null)
|
|
477
|
+
const result = await request(action, data)
|
|
478
|
+
if (result.install) {
|
|
479
|
+
setOffer(result.install)
|
|
480
|
+
} else {
|
|
481
|
+
setConnection(result)
|
|
482
|
+
setAdding(false)
|
|
483
|
+
setOffer(null)
|
|
484
|
+
}
|
|
485
|
+
} catch (error) {
|
|
486
|
+
if (action === 'connection-deploy') setOffer(null)
|
|
487
|
+
setError(error.message)
|
|
488
|
+
}
|
|
489
|
+
finally { setBusy(false) }
|
|
490
|
+
}
|
|
491
|
+
const active = connection?.active
|
|
492
|
+
const field = (name, label, attributes = {}) => h('label',{key:name},label,h('input',{
|
|
493
|
+
value:fields[name],onChange:e=>{setOffer(null);setError('');setFields({...fields,[name]:e.target.value})},disabled:busy,...attributes
|
|
494
|
+
}))
|
|
495
|
+
const controls = h('section',{className:'ops-connect','aria-label':'服务器连接'},
|
|
496
|
+
active && h('div',{className:'ops-connect-row'},
|
|
497
|
+
h('label',null,'服务器',h('select',{value:active,disabled:busy,
|
|
498
|
+
onChange:e=>connect('connection-select',{serverId:e.target.value})},
|
|
499
|
+
connection.servers.map(server=>h('option',{key:server.serverId,value:server.serverId},
|
|
500
|
+
server.host+' · '+server.endpoint+':'+server.port)))),
|
|
501
|
+
btn(adding ? '取消添加' : '添加服务器',()=>{setAdding(!adding);setError('');setOffer(null)},busy)),
|
|
502
|
+
connection && (!active || adding) && h('form',{onSubmit:e=>{
|
|
503
|
+
e.preventDefault()
|
|
504
|
+
if (!busy) connect('connection-add',fields)
|
|
505
|
+
}},
|
|
506
|
+
h('h2',null,'连接 Linux 服务器'),
|
|
507
|
+
h('div',{className:'ops-connect-fields'},
|
|
508
|
+
field('host','SSH 主机',{required:true,placeholder:'server.example.com'}),
|
|
509
|
+
field('port','SSH 端口',{required:true,type:'number',min:1,max:65535}),
|
|
510
|
+
field('user','SSH 用户',{required:true}),
|
|
511
|
+
field('fingerprint','服务器主机指纹',{required:true,placeholder:'SHA256:…'}),
|
|
512
|
+
field('keyPath','本机私钥路径(可选)',{placeholder:'~/.ssh/id_ed25519'})),
|
|
513
|
+
h('button',{type:'submit',className:'ops-primary',disabled:busy},busy ? '正在连接…' : '验证并连接')),
|
|
514
|
+
(!active || adding) && offer && h('section',{className:'ops-card','aria-label':'Linux 部署'},
|
|
515
|
+
h('h3',null,offer.grantOnly ? '授予运维读取权限' : '首次部署 Linux 运维服务'),
|
|
516
|
+
h('p',null,offer.user+' @ '+offer.host+':'+offer.port+
|
|
517
|
+
(offer.grantOnly ? '' : ' · '+offer.version)),
|
|
518
|
+
offer.confirmation ? h(R.Fragment,null,
|
|
519
|
+
h('p',null,offer.grantOnly ? '将 SSH 用户加入 server-ops-read 组,并重新连接。' :
|
|
520
|
+
'需要 root 或免密 sudo。将校验并安装发行包、启用 systemd 服务、授予本账号读取权限,再重新连接。'),
|
|
521
|
+
btn(busy ? '正在部署…' : offer.grantOnly ? '确认授权并连接' : '确认部署并连接',
|
|
522
|
+
()=>connect('connection-deploy',{confirmation:offer.confirmation}),busy,'ops-primary')) :
|
|
523
|
+
h('p',null,'当前 SSH 账号需要请服务器管理员执行以下命令,再验证并连接。'),
|
|
524
|
+
h('details',{open:!offer.confirmation || undefined},h('summary',null,'管理员安装指引'),
|
|
525
|
+
!offer.grantOnly && h('p',null,h('a',{href:offer.releaseUrl,target:'_blank',rel:'noopener noreferrer'},'下载同版本 Linux 安装包')),
|
|
526
|
+
h('pre',null,offer.instructions))),
|
|
527
|
+
!connection && (error ? btn('重试读取连接',refresh) : h('p',null,'正在读取连接设置…')),
|
|
528
|
+
error && h('p',{role:'alert'},error))
|
|
529
|
+
const selected = connection?.servers.find(server=>server.serverId===active)
|
|
530
|
+
return active ? h(Connection.Provider,{value:active},h(Dashboard,{
|
|
531
|
+
key:active,connectionControls:controls,connectionRecord:selected
|
|
532
|
+
})) :
|
|
533
|
+
h('main',{className:'ops-panel'},h('style',null,panelStyles),
|
|
534
|
+
h('div',{className:'ops-inner'},h('header',{className:'ops-header'},h('h1',null,'服务器运维')),controls))
|
|
535
|
+
}
|
|
536
|
+
function Dashboard({connectionControls,connectionRecord}) {
|
|
537
|
+
const api = useApi()
|
|
538
|
+
const [state,setState] = R.useState(null)
|
|
539
|
+
const [activity,setActivity] = R.useState(connectionRecord)
|
|
540
|
+
const [error,setError] = R.useState('')
|
|
541
|
+
const [tab,setTab] = R.useState('值班')
|
|
542
|
+
const [id,setId] = R.useState(null)
|
|
543
|
+
const [evidence,setEvidence] = R.useState(null)
|
|
544
|
+
const [eventError,setEventError] = R.useState('')
|
|
545
|
+
const [reportEnd,setReportEnd] = R.useState(null)
|
|
546
|
+
R.useEffect(() => {
|
|
547
|
+
let live = true, timer
|
|
548
|
+
async function refresh() {
|
|
549
|
+
try {
|
|
550
|
+
const snapshot = await api('overview')
|
|
551
|
+
if (live) {
|
|
552
|
+
setState(snapshot)
|
|
553
|
+
setActivity(snapshot.service)
|
|
554
|
+
setError('')
|
|
555
|
+
}
|
|
556
|
+
} catch (error) {
|
|
557
|
+
if (live) setError(error.message)
|
|
558
|
+
try {
|
|
559
|
+
const result = await request('connection-status')
|
|
560
|
+
if (live) setActivity(result.servers.find(server=>server.serverId===connectionRecord.serverId))
|
|
561
|
+
} catch {}
|
|
562
|
+
}
|
|
563
|
+
if (live) timer = setTimeout(refresh, 2500)
|
|
564
|
+
}
|
|
565
|
+
refresh()
|
|
566
|
+
return () => { live=false; clearTimeout(timer) }
|
|
567
|
+
}, [api,connectionRecord.serverId])
|
|
568
|
+
R.useEffect(() => {
|
|
569
|
+
if (tab !== '事件' || !id) return
|
|
570
|
+
let live = true
|
|
571
|
+
api('event',{id}).then(result=>{if (live) setEvidence(result)},error=>{
|
|
572
|
+
if (live) setEventError(error.message)
|
|
573
|
+
})
|
|
574
|
+
return () => { live=false }
|
|
575
|
+
}, [api,tab,id])
|
|
576
|
+
function openEvent(eventId) {
|
|
577
|
+
if (eventId !== id) {
|
|
578
|
+
setEvidence(null)
|
|
579
|
+
setEventError('')
|
|
580
|
+
setId(eventId)
|
|
581
|
+
}
|
|
582
|
+
setTab('事件')
|
|
583
|
+
}
|
|
584
|
+
const report = state?.reports.find(row=>row.end===reportEnd) ?? state?.reports[0]
|
|
585
|
+
const eventLink = event => h('p',{key:event.id},btn(event.signal+' · '+fmt(event.opened),()=>openEvent(event.id)),
|
|
586
|
+
' · '+(event.closed ? '已恢复' : '待核实'))
|
|
587
|
+
return h('main',{className:'ops-panel'},h('style',null,panelStyles),
|
|
588
|
+
h('div',{className:'ops-inner'},
|
|
589
|
+
h('header',{className:'ops-header'},h('h1',null,'服务器运维')),
|
|
590
|
+
connectionControls,
|
|
591
|
+
h('nav',{'aria-label':'运维工作台'},...['值班','运维 Agent','日报',...(id ? ['事件'] : [])].map(name=>
|
|
592
|
+
h('button',{key:name,type:'button','aria-current':name===tab?'page':undefined,onClick:()=>setTab(name)},name))),
|
|
593
|
+
error && h('p',{role:'alert'},error),
|
|
594
|
+
(error || !state) && h('section',{className:'brief-section','aria-label':'上次连接记录'},
|
|
595
|
+
fact('DSH 最近 SSH 连接',fmt(activity?.lastConnectedAt)),
|
|
596
|
+
fact('最近同步',fmt(activity?.lastSyncedAt))),
|
|
597
|
+
!state && !error && h('p',{role:'status'},'正在同步服务器采样…'),
|
|
598
|
+
state && tab === '值班' && h(R.Fragment,null,
|
|
599
|
+
h(ServerStatus,{host:state.service.host,samples:state.samples,clock:state.clock,
|
|
600
|
+
interval:state.sshInterval,disconnected:!!error,openEvent,service:state.service}),
|
|
601
|
+
!state.service.latestSample && !error && h('p',{role:'status'},'正在等待首条容量采样…'),
|
|
602
|
+
h('section',{className:'ops-card'},h('h2',null,'事件'),
|
|
603
|
+
state.events.length ? state.events.map(eventLink) : h('p',null,'暂无事件。'))),
|
|
604
|
+
state && tab === '运维 Agent' && h(OperatorPage,{hosts:state.agentHosts}),
|
|
605
|
+
state && tab === '日报' && h('section',{className:'ops-card'},
|
|
606
|
+
h('h2',null,'运维日报'),
|
|
607
|
+
!report ? h('p',null,'等待首份北京时间 07:00 日报。') : h(R.Fragment,null,
|
|
608
|
+
h('label',null,'选择日报 ',h('select',{value:report.end,onChange:event=>setReportEnd(Number(event.target.value))},
|
|
609
|
+
...state.reports.map(row=>h('option',{key:row.end,value:row.end},fmt(row.end))))),
|
|
610
|
+
fact('覆盖窗口',fmt(report.body.start)+' 至 '+fmt(report.end)),
|
|
611
|
+
fact('生成时间',fmt(report.created)),
|
|
612
|
+
h('h3',null,'关联事件'),
|
|
613
|
+
report.body.cases.length ? report.body.cases.map(eventLink) : h('p',null,'本窗口无事件。'),
|
|
614
|
+
h('h3',null,'采样与缺测时段'),
|
|
615
|
+
...Object.entries(report.body.coverage).map(([name,coverage])=>
|
|
616
|
+
h('details',{key:name},h('summary',null,name+' · '+coverage.gaps.length+' 段缺测'),
|
|
617
|
+
coverage.last && fact('最后采样',fmt(coverage.last.ts)),
|
|
618
|
+
coverage.last && json(JSON.parse(coverage.last.value)),
|
|
619
|
+
...coverage.gaps.map(([start,end])=>h('p',{key:start},fmt(start)+' 至 '+fmt(end))))))),
|
|
620
|
+
state && tab === '事件' && h('section',{className:'ops-card'},
|
|
621
|
+
h('h2',null,evidence?.event.signal ?? '事件'),
|
|
622
|
+
eventError ? h('p',{role:'alert'},eventError) : !evidence ? h('p',null,'正在读取原始观测…') : h(R.Fragment,null,
|
|
623
|
+
fact('事件编号',evidence.event.id),fact('发生时间',fmt(evidence.event.opened)),
|
|
624
|
+
fact('恢复时间',fmt(evidence.event.closed)),
|
|
625
|
+
h('h3',null,'观测证据'),
|
|
626
|
+
...evidence.samples.map(sample=>h('details',{key:sample.id},h('summary',null,
|
|
627
|
+
'#'+sample.id+' · '+sample.signal+' · '+fmt(sample.ts)+' · '+labels[sample.state]),json(JSON.parse(sample.value))))))))
|
|
628
|
+
}
|
|
629
|
+
return {
|
|
630
|
+
inject: ['slots', 'layout', 'sessions', 'workspaces', 'uiWorkspace'],
|
|
631
|
+
apply(ctx) {
|
|
632
|
+
client = ctx
|
|
633
|
+
ctx.slots.inject('main', () => ctx.slots.register({name:'main',key:panel},Page))
|
|
634
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
635
|
+
ctx.slots.register({name:'sidebar.panellist',id:panel,order:42,label:()=>'服务器运维'},
|
|
636
|
+
() => h('span',{'aria-hidden':true},'▤')))
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const serviceProtocol = 1
|
|
2
|
+
export const sshCommand = '/usr/local/bin/dsh-server-ops'
|
|
3
|
+
export const maxRequestBytes = 1024 * 1024
|
|
4
|
+
export const maxResponseBytes = 16 * 1024 * 1024
|
|
5
|
+
export const requestTimeout = 12_000
|
|
6
|
+
export const serverIdPattern = /^[a-f0-9]{64}$/
|
|
7
|
+
export const eventIdPattern = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/
|