dsh-contextos-devops 0.0.0-stage → 1.48.32
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/LICENSE +21 -0
- package/README.md +207 -2
- package/assets/avatar.jpg +0 -0
- package/assets/client.css +3316 -0
- package/assets/icon-180.png +0 -0
- package/build/client.mjs +64 -0
- package/client.js +7622 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +15 -0
- package/index.js +345 -0
- package/lib/base/env.js +22 -0
- package/lib/base/field.js +25 -0
- package/lib/base/http.js +140 -0
- package/lib/base/platform.js +33 -0
- package/lib/base/registry.js +186 -0
- package/lib/base/state.js +66 -0
- package/lib/base/table.js +47 -0
- package/lib/base/texttable.js +26 -0
- package/lib/base/url.js +178 -0
- package/lib/core/README.md +17 -0
- package/lib/core/apps.js +675 -0
- package/lib/core/auth.js +110 -0
- package/lib/core/avatar.js +289 -0
- package/lib/core/backup.js +105 -0
- package/lib/core/codegen.js +401 -0
- package/lib/core/copilot.js +419 -0
- package/lib/core/data.js +157 -0
- package/lib/core/device.js +148 -0
- package/lib/core/files.js +152 -0
- package/lib/core/gobuild.js +63 -0
- package/lib/core/iam.js +122 -0
- package/lib/core/identity.js +22 -0
- package/lib/core/nodes.js +627 -0
- package/lib/core/ops.js +306 -0
- package/lib/core/project.js +393 -0
- package/lib/core/spaces.js +406 -0
- package/lib/core/terminal.js +137 -0
- package/lib/core/terminal2.js +141 -0
- package/lib/core/users.js +51 -0
- package/lib/core/vocab.js +158 -0
- package/lib/misc/async.js +15 -0
- package/lib/misc/shell.js +27 -0
- package/lib/misc/static.js +33 -0
- package/locale/en.json +10 -0
- package/locale/zh.json +10 -0
- package/package.json +92 -4
- package/src/client/README.md +37 -0
- package/src/client/parts/00-prelude.js +315 -0
- package/src/client/parts/05-bootstrap.js +61 -0
- package/src/client/parts/08-store.js +85 -0
- package/src/client/parts/10-ui.js +188 -0
- package/src/client/parts/12-debug.js +361 -0
- package/src/client/parts/15-layout.js +86 -0
- package/src/client/parts/20-devworkspace.js +789 -0
- package/src/client/parts/25-editor-ui.js +28 -0
- package/src/client/parts/30-modals.js +85 -0
- package/src/client/parts/32-cards.js +176 -0
- package/src/client/parts/34-forms.js +176 -0
- package/src/client/parts/36-data.js +267 -0
- package/src/client/parts/40-project.js +430 -0
- package/src/client/parts/45-map.js +109 -0
- package/src/client/parts/46-pm.js +158 -0
- package/src/client/parts/47-three.js +324 -0
- package/src/client/parts/49-msg.js +167 -0
- package/src/client/parts/50-chat.js +1422 -0
- package/src/client/parts/51-pmselection.js +31 -0
- package/src/client/parts/52-pmdata.js +29 -0
- package/src/client/parts/55-pm.js +146 -0
- package/src/client/parts/58-config.js +381 -0
- package/src/client/parts/59-monitor.js +262 -0
- package/src/client/parts/60-page.js +1518 -0
- package/src/client/styles/kit.css +20 -0
- package/src/client/styles/main.css +3294 -0
- package/src/client/styles/tokens.css +2 -0
- package/vendor/leaflet/leaflet.css +661 -0
- package/vendor/leaflet/leaflet.js +6 -0
- package/vendor/three/three.module.js +53044 -0
- package/vendor/xterm/addon-fit.js +2 -0
- package/vendor/xterm/xterm.css +218 -0
- package/vendor/xterm/xterm.js +2 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/* ============ 监控视图:数字大屏 / 数字孪生 ============ */
|
|
2
|
+
function MonitorDonut({ items, size = 132 }) {
|
|
3
|
+
const total = items.reduce((a, b) => a + b.value, 0) || 1;
|
|
4
|
+
const R = size / 2 - 10, C = 2 * Math.PI * R;
|
|
5
|
+
let acc = 0;
|
|
6
|
+
return h('svg', { width: size, height: size, viewBox: `0 0 ${size} ${size}`, className: 'cx-mon-donut' },
|
|
7
|
+
h('circle', { cx: size / 2, cy: size / 2, r: R, fill: 'none', stroke: 'rgba(var(--cx-hue-rgb),.12)', strokeWidth: 14 }),
|
|
8
|
+
items.map((it, i) => {
|
|
9
|
+
const len = (it.value / total) * C;
|
|
10
|
+
const el = h('circle', {
|
|
11
|
+
key: i, cx: size / 2, cy: size / 2, r: R, fill: 'none', stroke: it.color, strokeWidth: 14,
|
|
12
|
+
strokeDasharray: `${len} ${C - len}`, strokeDashoffset: -acc,
|
|
13
|
+
transform: `rotate(-90 ${size / 2} ${size / 2})`, strokeLinecap: 'butt', opacity: .92,
|
|
14
|
+
});
|
|
15
|
+
acc += len;
|
|
16
|
+
return el;
|
|
17
|
+
}),
|
|
18
|
+
h('text', { x: size / 2, y: size / 2 - 2, textAnchor: 'middle', className: 'cx-mon-donut-n' }, String(total)),
|
|
19
|
+
h('text', { x: size / 2, y: size / 2 + 16, textAnchor: 'middle', className: 'cx-mon-donut-l' }, 'TOTAL'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function MonitorSpark({ series, width = 320, height = 92 }) {
|
|
23
|
+
const data = series.length ? series : [0];
|
|
24
|
+
const max = Math.max(1, ...data);
|
|
25
|
+
const step = width / Math.max(1, data.length - 1);
|
|
26
|
+
const pts = data.map((v, i) => [i * step, height - (v / max) * (height - 8) - 4]);
|
|
27
|
+
const line = pts.map((p, i) => `${i ? 'L' : 'M'}${p[0].toFixed(1)},${p[1].toFixed(1)}`).join(' ');
|
|
28
|
+
const area = `${line} L${width},${height} L0,${height} Z`;
|
|
29
|
+
return h('svg', { viewBox: `0 0 ${width} ${height}`, className: 'cx-mon-spark', preserveAspectRatio: 'none' },
|
|
30
|
+
h('defs', null, h('linearGradient', { id: 'cxMonGrad', x1: 0, y1: 0, x2: 0, y2: 1 },
|
|
31
|
+
h('stop', { offset: '0%', stopColor: 'var(--cx-cyan)', stopOpacity: .35 }),
|
|
32
|
+
h('stop', { offset: '100%', stopColor: 'var(--cx-cyan)', stopOpacity: 0 }))),
|
|
33
|
+
h('path', { d: area, fill: 'url(#cxMonGrad)' }),
|
|
34
|
+
h('path', { d: line, fill: 'none', stroke: 'var(--cx-cyan)', strokeWidth: 1.6, strokeLinejoin: 'round' }),
|
|
35
|
+
pts.map((p, i) => (i % 6 === 0 ? h('circle', { key: i, cx: p[0], cy: p[1], r: 1.8, fill: 'var(--cx-cyan)' }) : null)));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function MonitorTwin({ nodes, spaces, apps }) {
|
|
39
|
+
const ref = useRef(null);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const cv = ref.current;
|
|
42
|
+
if (!cv) return;
|
|
43
|
+
const g = cv.getContext('2d');
|
|
44
|
+
let w = 0, h = 0, raf = 0, t = 0, alive = true;
|
|
45
|
+
const dots = [];
|
|
46
|
+
const n = Math.max(6, Math.min(26, 6 + (nodes || []).length));
|
|
47
|
+
for (let i = 0; i < n; i++) {
|
|
48
|
+
const a = (i / n) * Math.PI * 2;
|
|
49
|
+
dots.push({ a, r: 0.55 + ((i * 37) % 30) / 100, s: 0.15 + ((i * 13) % 9) / 60, kind: i % 7 === 0 ? 'hub' : 'node' });
|
|
50
|
+
}
|
|
51
|
+
const resize = () => { const b = cv.getBoundingClientRect(); w = cv.width = Math.max(1, Math.round(b.width)); h = cv.height = Math.max(1, Math.round(b.height)); };
|
|
52
|
+
resize();
|
|
53
|
+
const ro = new ResizeObserver(resize); ro.observe(cv);
|
|
54
|
+
const draw = () => {
|
|
55
|
+
raf = 0;
|
|
56
|
+
if (!alive) return;
|
|
57
|
+
raf = requestAnimationFrame(draw);
|
|
58
|
+
if (document.hidden) return;
|
|
59
|
+
t += 0.012;
|
|
60
|
+
g.clearRect(0, 0, w, h);
|
|
61
|
+
const cx = w / 2, cy = h / 2, R = Math.min(w, h) * 0.36;
|
|
62
|
+
g.strokeStyle = 'rgba(62,231,255,.10)'; g.lineWidth = 1;
|
|
63
|
+
for (let k = 1; k <= 3; k++) { g.beginPath(); g.arc(cx, cy, R * k / 3, 0, 6.283); g.stroke(); }
|
|
64
|
+
const pts = dots.map((d) => [cx + Math.cos(d.a + t * d.s) * R * d.r, cy + Math.sin(d.a + t * d.s) * R * d.r * 0.72]);
|
|
65
|
+
g.strokeStyle = 'rgba(62,231,255,.22)';
|
|
66
|
+
for (let i = 0; i < pts.length; i++) {
|
|
67
|
+
for (let j = i + 1; j < pts.length; j++) {
|
|
68
|
+
if ((i * 7 + j * 3) % 11 !== 0) continue;
|
|
69
|
+
g.beginPath(); g.moveTo(pts[i][0], pts[i][1]); g.lineTo(pts[j][0], pts[j][1]); g.stroke();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (let i = 0; i < pts.length; i++) {
|
|
73
|
+
const p = pts[i], d = dots[i];
|
|
74
|
+
const pulse = 0.6 + 0.4 * Math.sin(t * 2 + i);
|
|
75
|
+
g.beginPath();
|
|
76
|
+
g.fillStyle = d.kind === 'hub' ? `rgba(255,190,74,${pulse})` : `rgba(62,231,255,${pulse})`;
|
|
77
|
+
g.arc(p[0], p[1], d.kind === 'hub' ? 4 : 2.4, 0, 6.283); g.fill();
|
|
78
|
+
if (d.kind === 'hub') { g.strokeStyle = 'rgba(255,190,74,.35)'; g.beginPath(); g.arc(p[0], p[1], 10 + 4 * Math.sin(t * 2), 0, 6.283); g.stroke(); }
|
|
79
|
+
}
|
|
80
|
+
g.fillStyle = 'rgba(62,231,255,.85)'; g.beginPath(); g.arc(cx, cy, 5, 0, 6.283); g.fill();
|
|
81
|
+
g.strokeStyle = 'rgba(62,231,255,.4)'; g.beginPath(); g.arc(cx, cy, 14 + 4 * Math.sin(t * 2), 0, 6.283); g.stroke();
|
|
82
|
+
};
|
|
83
|
+
raf = requestAnimationFrame(draw);
|
|
84
|
+
return () => { alive = false; cancelAnimationFrame(raf); ro.disconnect(); };
|
|
85
|
+
}, [nodes]);
|
|
86
|
+
return h('canvas', { className: 'cx-mon-twin', ref });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/* ===== 面板看板:参考 Grafana,面板与数据源都可加 ===== */
|
|
91
|
+
const MON_PANELS = 'dsh-contextos-devops:monitor-panels';
|
|
92
|
+
const MON_DEFAULT = [
|
|
93
|
+
{ id: 'n1', type: 'stat', title: '服务节点', src: { kind: 'nodes' }, w: 3, refresh: 0 },
|
|
94
|
+
{ id: 'n2', type: 'stat', title: '项目空间', src: { kind: 'spaces' }, w: 3, refresh: 0 },
|
|
95
|
+
{ id: 'n3', type: 'table', title: '节点健康', src: { kind: 'op', op: 'sampleNodes' }, w: 6, refresh: 10 },
|
|
96
|
+
{ id: 'n4', type: 'query', title: 'runtime', src: { kind: 'cmd', node: 9191, command: 'runtime' }, w: 4, refresh: 10 },
|
|
97
|
+
{ id: 'n5', type: 'iframe', title: '管理后台', src: { kind: 'url', url: '/c/admin', node: 9191 }, w: 8, refresh: 0 },
|
|
98
|
+
];
|
|
99
|
+
const monLoad = () => { const v = cxRead(MON_PANELS, null); return Array.isArray(v) && v.length ? v : MON_DEFAULT; };
|
|
100
|
+
const monSave = (v) => cxWrite(MON_PANELS, v.slice(0, 24));
|
|
101
|
+
|
|
102
|
+
function MonitorPanel({ p, data, onEdit, onDel, onReload, zh }) {
|
|
103
|
+
const body = () => {
|
|
104
|
+
if (p.type === 'iframe') {
|
|
105
|
+
const url = /^https?:/.test(p.src.url) ? p.src.url : `http://127.0.0.1:${p.src.node || 9191}${p.src.url || '/'}`;
|
|
106
|
+
return h('iframe', { className: 'cx-mon-frame', src: url, title: p.title, sandbox: 'allow-same-origin allow-scripts allow-forms' });
|
|
107
|
+
}
|
|
108
|
+
if (!data || data.loading) return h('div', { className: 'cx-mon-empty' }, zh ? '加载中…' : 'loading…');
|
|
109
|
+
if (data.error) return h('div', { className: 'cx-mon-empty err' }, String(data.error).slice(0, 120));
|
|
110
|
+
const r = data.value || {};
|
|
111
|
+
if (p.type === 'stat') return h('div', { className: 'cx-mon-stat' }, h('b', null, String(r.value ?? '—')), h('span', null, r.sub || ''));
|
|
112
|
+
if (p.type === 'table') {
|
|
113
|
+
const cols = (r.columns || []).slice(0, 5);
|
|
114
|
+
return h('div', { className: 'cx-mon-tbl' },
|
|
115
|
+
h('div', { className: 'h' }, cols.map((c) => h('span', { key: c }, String(c)))),
|
|
116
|
+
(r.rows || []).slice(0, 6).map((row, i) => h('div', { key: i, className: 'r' }, cols.map((c) => h('span', { key: c }, String(row[c] ?? '').slice(0, 18))))));
|
|
117
|
+
}
|
|
118
|
+
// query:单值 / 键值
|
|
119
|
+
if (r.fields) return h('div', { className: 'cx-mon-kv' }, Object.entries(r.fields).slice(0, 6).map(([k, v]) => h('div', { key: k }, h('span', null, k), h('b', null, String(v).slice(0, 24)))));
|
|
120
|
+
if (r.result) return h('div', { className: 'cx-mon-stat' }, h('b', { className: 'sm' }, String(r.result).slice(0, 40)));
|
|
121
|
+
return h('div', { className: 'cx-mon-empty' }, `${r.status ?? ''} ${r.count || ''} · ${r.ms ?? ''}ms`);
|
|
122
|
+
};
|
|
123
|
+
return h('section', { className: 'cx-mon-panel cx-mon-bo', style: { gridColumn: `span ${Math.max(2, Math.min(12, p.w || 3))}` } },
|
|
124
|
+
h('div', { className: 'cx-mon-pt' },
|
|
125
|
+
h('span', null, p.title || p.id),
|
|
126
|
+
h('span', { className: 'cx-mon-bo-act' },
|
|
127
|
+
h('button', { className: 'cx-term-act', onClick: () => onReload(p) }, zh ? '刷新' : 'Refresh'),
|
|
128
|
+
h('button', { className: 'cx-term-act', onClick: () => onEdit(p) }, zh ? '编辑' : 'Edit'),
|
|
129
|
+
h('button', { className: 'cx-term-act danger', onClick: () => onDel(p) }, zh ? '删除' : 'Delete'))),
|
|
130
|
+
h('div', { className: 'cx-mon-bo-body' }, body()));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function MonitorBoard({ nodes, spaces, locale, onNotify }) {
|
|
134
|
+
const zh = locale === 'zh';
|
|
135
|
+
const [panels, setPanels] = useState(monLoad);
|
|
136
|
+
const [data, setData] = useState({});
|
|
137
|
+
const [edit, setEdit] = useState(null);
|
|
138
|
+
const [tick, setTick] = useState(0);
|
|
139
|
+
useEffect(() => { monSave(panels); }, [panels]);
|
|
140
|
+
useEffect(() => { const t = setInterval(() => setTick((x) => x + 1), 5000); return () => clearInterval(t); }, []);
|
|
141
|
+
const load = async (p) => {
|
|
142
|
+
if (p.type === 'iframe') return;
|
|
143
|
+
setData((d) => ({ ...d, [p.id]: { loading: true } }));
|
|
144
|
+
try {
|
|
145
|
+
let value;
|
|
146
|
+
if (p.src.kind === 'nodes') value = { value: (nodes || []).length, sub: `${(nodes || []).filter((n) => n.state === 'running').length} running` };
|
|
147
|
+
else if (p.src.kind === 'spaces') value = { value: (spaces || []).length, sub: `${(spaces || []).filter((s) => s.status === 'running').length} online` };
|
|
148
|
+
else if (p.src.kind === 'op') value = await api(p.src.op, p.src.params || {});
|
|
149
|
+
else value = await api('monitorQuery', { node: p.src.node || 9191, space: p.src.space || '', command: p.src.command, action: p.src.action || '', params: p.src.params || {} });
|
|
150
|
+
setData((d) => ({ ...d, [p.id]: { value, at: Date.now() } }));
|
|
151
|
+
} catch (e) {
|
|
152
|
+
setData((d) => ({ ...d, [p.id]: { error: e.message || String(e) } }));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
panels.forEach((p) => { if (p.type === 'iframe') return; const due = p.refresh > 0 ? tick % Math.max(1, Math.round(p.refresh / 5)) === 0 : true; if (tick === 0 || due) load(p); });
|
|
157
|
+
}, [tick, panels.length]);
|
|
158
|
+
const startAdd = () => setEdit({ id: 'p' + Date.now().toString(36), type: 'query', title: zh ? '新面板' : 'New panel', w: 4, refresh: 10, src: { kind: 'cmd', node: 9191, command: 'runtime', params: {} } });
|
|
159
|
+
const saveEdit = () => { setPanels((list) => { const i = list.findIndex((x) => x.id === edit.id); return i >= 0 ? list.map((x) => (x.id === edit.id ? edit : x)) : [...list, edit]; }); setEdit(null); };
|
|
160
|
+
return h('div', { className: 'cx-mon-board' },
|
|
161
|
+
h('div', { className: 'cx-mon-board-h' },
|
|
162
|
+
h('span', { className: 't' }, zh ? '面板看板' : 'PANELS'),
|
|
163
|
+
h('span', { className: 's' }, zh ? '数据源 = 节点 + 空间 + 命令 + 参数' : 'source = node + space + command + params'),
|
|
164
|
+
h('button', { className: 'cx-btn xs pri', onClick: startAdd }, zh ? '+ 添加面板' : '+ Panel')),
|
|
165
|
+
h('div', { className: 'cx-mon-board-grid' }, panels.map((p) => h(MonitorPanel, { key: p.id, p, data: data[p.id], zh, onEdit: setEdit, onDel: (x) => setPanels((l) => l.filter((y) => y.id !== x.id)), onReload: load }))),
|
|
166
|
+
edit ? h('div', { className: 'cx-mon-ed' },
|
|
167
|
+
h('div', { className: 'cx-mon-ed-h' }, zh ? '面板设置' : 'Panel'),
|
|
168
|
+
h('label', null, zh ? '标题' : 'Title', h('input', { value: edit.title, onChange: (e) => setEdit({ ...edit, title: e.target.value }) })),
|
|
169
|
+
h('label', null, zh ? '类型' : 'Type', h('select', { value: edit.type, onChange: (e) => setEdit({ ...edit, type: e.target.value }) },
|
|
170
|
+
h('option', { value: 'stat' }, zh ? '数值' : 'Stat'),
|
|
171
|
+
h('option', { value: 'table' }, zh ? '表格' : 'Table'),
|
|
172
|
+
h('option', { value: 'query' }, zh ? '命令' : 'Command'),
|
|
173
|
+
h('option', { value: 'iframe' }, zh ? '内嵌网页' : 'Iframe'))),
|
|
174
|
+
h('label', null, zh ? '数据源类型' : 'Source', h('select', { value: edit.src.kind, onChange: (e) => setEdit({ ...edit, src: { ...edit.src, kind: e.target.value } }) },
|
|
175
|
+
h('option', { value: 'nodes' }, zh ? '节点列表' : 'Nodes'),
|
|
176
|
+
h('option', { value: 'spaces' }, zh ? '空间列表' : 'Spaces'),
|
|
177
|
+
h('option', { value: 'op' }, zh ? '内置数据' : 'Builtin'),
|
|
178
|
+
h('option', { value: 'cmd' }, zh ? '命令' : 'Command'),
|
|
179
|
+
h('option', { value: 'url' }, zh ? '网址' : 'URL'))),
|
|
180
|
+
edit.src.kind === 'cmd' ? h('div', { className: 'cx-mon-ed-row' },
|
|
181
|
+
h('label', null, 'node', h('input', { value: edit.src.node || 9191, onChange: (e) => setEdit({ ...edit, src: { ...edit.src, node: Number(e.target.value) || 9191 } }) })),
|
|
182
|
+
h('label', null, 'space', h('input', { value: edit.src.space || '', onChange: (e) => setEdit({ ...edit, src: { ...edit.src, space: e.target.value } }) })),
|
|
183
|
+
h('label', null, 'command', h('input', { value: edit.src.command || '', onChange: (e) => setEdit({ ...edit, src: { ...edit.src, command: e.target.value } }) })),
|
|
184
|
+
h('label', null, 'action', h('input', { value: edit.src.action || '', onChange: (e) => setEdit({ ...edit, src: { ...edit.src, action: e.target.value } }) }))) : null,
|
|
185
|
+
edit.src.kind === 'url' ? h('div', { className: 'cx-mon-ed-row' },
|
|
186
|
+
h('label', null, 'node', h('input', { value: edit.src.node || 9191, onChange: (e) => setEdit({ ...edit, src: { ...edit.src, node: Number(e.target.value) || 9191 } }) })),
|
|
187
|
+
h('label', null, 'url', h('input', { value: edit.src.url || '', onChange: (e) => setEdit({ ...edit, src: { ...edit.src, url: e.target.value } }) }))) : null,
|
|
188
|
+
h('label', null, zh ? '宽度(1-12 栅格)' : 'Width', h('input', { type: 'number', min: 2, max: 12, value: edit.w || 3, onChange: (e) => setEdit({ ...edit, w: Number(e.target.value) || 3 }) })),
|
|
189
|
+
h('label', null, zh ? '刷新秒数(0=不刷新)' : 'Refresh', h('input', { type: 'number', min: 0, max: 600, value: edit.refresh || 0, onChange: (e) => setEdit({ ...edit, refresh: Number(e.target.value) || 0 }) })),
|
|
190
|
+
h('div', { className: 'cx-mon-ed-f' },
|
|
191
|
+
h('button', { className: 'cx-btn xs', onClick: () => setEdit(null) }, zh ? '取消' : 'Cancel'),
|
|
192
|
+
h('button', { className: 'cx-btn xs pri', onClick: saveEdit }, zh ? '保存' : 'Save'))) : null);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function MonitorView({ nodes, spaces, apps, events, logs, reqLog, locale, onRefresh }) {
|
|
196
|
+
const zh = locale === 'zh';
|
|
197
|
+
const [, tick] = useState(0);
|
|
198
|
+
useEffect(() => { const t = setInterval(() => tick((x) => x + 1), 2000); return () => clearInterval(t); }, []);
|
|
199
|
+
const now = new Date();
|
|
200
|
+
const running = (nodes || []).filter((n) => n.state === 'running').length;
|
|
201
|
+
const offline = (nodes || []).filter((n) => n.state && n.state !== 'running').length;
|
|
202
|
+
const runningApps = (apps || []).length;
|
|
203
|
+
const reqs = (reqLog || []).length;
|
|
204
|
+
const errs = (reqLog || []).filter((r) => /err|fail|×|500/i.test(String(r.status || r.op || ''))).length;
|
|
205
|
+
const errRate = reqs ? Math.round((errs / reqs) * 1000) / 10 : 0;
|
|
206
|
+
const series = (reqLog || []).slice(-24).map((r) => Number(r.ms) || 60);
|
|
207
|
+
const kpis = [
|
|
208
|
+
{ k: zh ? '节点' : 'NODES', v: (nodes || []).length, sub: `${running} ${zh ? '运行中' : 'running'}`, tone: 'cyan' },
|
|
209
|
+
{ k: zh ? '项目空间' : 'SPACES', v: (spaces || []).length, sub: `${(spaces || []).filter((s) => s.status === 'running').length} ${zh ? '在线' : 'online'}`, tone: 'green' },
|
|
210
|
+
{ k: zh ? '应用' : 'APPS', v: runningApps, sub: zh ? '最近加载' : 'loaded', tone: 'green' },
|
|
211
|
+
{ k: zh ? '请求' : 'REQUESTS', v: reqs, sub: zh ? '本次会话' : 'session', tone: 'cyan' },
|
|
212
|
+
{ k: zh ? '错误率' : 'ERR RATE', v: `${errRate}%`, sub: `${errs} ${zh ? '次' : 'errs'}`, tone: errRate > 5 ? 'rose' : 'amber' },
|
|
213
|
+
{ k: zh ? '事件' : 'EVENTS', v: (events || []).length, sub: `${(logs || []).length} ${zh ? '日志' : 'logs'}`, tone: 'amber' },
|
|
214
|
+
];
|
|
215
|
+
const donut = [
|
|
216
|
+
{ value: running, color: 'var(--cx-green)' },
|
|
217
|
+
{ value: offline, color: 'var(--cx-amber)' },
|
|
218
|
+
{ value: Math.max(0, (nodes || []).length - running - offline), color: 'rgba(var(--cx-hue-rgb),.35)' },
|
|
219
|
+
];
|
|
220
|
+
const spaceBars = (spaces || []).slice(0, 6).map((s) => ({ name: s.name, value: (apps || []).filter((a) => a.space === s.name).length || 1 }));
|
|
221
|
+
const maxBar = Math.max(1, ...spaceBars.map((b) => b.value));
|
|
222
|
+
const feed = (events || []).slice(-8).reverse();
|
|
223
|
+
return h('div', { className: 'cx-monitor' },
|
|
224
|
+
h(MonitorBoard, { nodes, spaces, locale }),
|
|
225
|
+
h('div', { className: 'cx-mon-head' },
|
|
226
|
+
h('div', null,
|
|
227
|
+
h('div', { className: 'cx-mon-title' }, zh ? '数字孪生 · 运行监控' : 'DIGITAL TWIN · LIVE MONITOR'),
|
|
228
|
+
h('div', { className: 'cx-mon-sub' }, `${now.toLocaleDateString()} ${now.toLocaleTimeString()} · ${zh ? '每 2 秒刷新' : 'refresh 2s'}`)),
|
|
229
|
+
h('div', { className: 'cx-mon-head-r' },
|
|
230
|
+
h('span', { className: 'cx-mon-live' }, '● LIVE'),
|
|
231
|
+
h('button', { className: 'cx-term-act', onClick: onRefresh }, zh ? '刷新' : 'Refresh'))),
|
|
232
|
+
h('div', { className: 'cx-mon-kpis' }, kpis.map((k) => h('div', { key: k.k, className: `cx-mon-kpi tone-${k.tone}` },
|
|
233
|
+
h('div', { className: 'k' }, k.k), h('div', { className: 'v' }, String(k.v)), h('div', { className: 's' }, k.sub)))),
|
|
234
|
+
h('div', { className: 'cx-mon-grid' },
|
|
235
|
+
h('section', { className: 'cx-mon-panel' },
|
|
236
|
+
h('div', { className: 'cx-mon-pt' }, zh ? '请求耗时趋势' : 'LATENCY TREND'),
|
|
237
|
+
h(MonitorSpark, { series }),
|
|
238
|
+
h('div', { className: 'cx-mon-legend' }, h('i', { className: 'dot cyan' }), zh ? '耗时 ms · 最近 24 次调用' : 'ms · last 24 calls')),
|
|
239
|
+
h('section', { className: 'cx-mon-panel mid' },
|
|
240
|
+
h('div', { className: 'cx-mon-pt' }, zh ? '孪生拓扑' : 'TWIN TOPOLOGY'),
|
|
241
|
+
h(MonitorTwin, { nodes, spaces, apps }),
|
|
242
|
+
h('div', { className: 'cx-mon-legend' }, h('i', { className: 'dot cyan' }), zh ? '节点' : 'node', h('i', { className: 'dot amber' }), zh ? '枢纽' : 'hub')),
|
|
243
|
+
h('section', { className: 'cx-mon-panel' },
|
|
244
|
+
h('div', { className: 'cx-mon-pt' }, zh ? '节点状态占比' : 'NODE STATUS'),
|
|
245
|
+
h('div', { className: 'cx-mon-donut-wrap' }, h(MonitorDonut, { items: donut }),
|
|
246
|
+
h('ul', { className: 'cx-mon-keys' },
|
|
247
|
+
h('li', null, h('i', { className: 'dot green' }), zh ? '运行' : 'running', h('b', null, running)),
|
|
248
|
+
h('li', null, h('i', { className: 'dot amber' }), zh ? '离线' : 'offline', h('b', null, offline)))))),
|
|
249
|
+
h('div', { className: 'cx-mon-grid2' },
|
|
250
|
+
h('section', { className: 'cx-mon-panel' },
|
|
251
|
+
h('div', { className: 'cx-mon-pt' }, zh ? '空间应用分布' : 'APPS BY SPACE'),
|
|
252
|
+
spaceBars.length ? spaceBars.map((b) => h('div', { key: b.name, className: 'cx-mon-bar' },
|
|
253
|
+
h('span', { className: 'n' }, b.name),
|
|
254
|
+
h('span', { className: 't' }, h('i', { style: { width: (b.value / maxBar) * 100 + '%' } })),
|
|
255
|
+
h('span', { className: 'v' }, String(b.value)))) : h('div', { className: 'cx-mon-empty' }, zh ? '暂无空间' : 'no spaces')),
|
|
256
|
+
h('section', { className: 'cx-mon-panel' },
|
|
257
|
+
h('div', { className: 'cx-mon-pt' }, zh ? '实时事件' : 'EVENT STREAM'),
|
|
258
|
+
feed.length ? feed.map((e, i) => h('div', { key: i, className: 'cx-mon-feed' },
|
|
259
|
+
h('span', { className: 't' }, String(e.t || '').slice(0, 8)),
|
|
260
|
+
h('span', { className: 'o' }, String(e.op || e.kind || '')), h('span', { className: 's' }, String(e.status || e.detail || '').slice(0, 28))))
|
|
261
|
+
: h('div', { className: 'cx-mon-empty' }, zh ? '暂无事件' : 'no events'))));
|
|
262
|
+
}
|