Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | 1x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 59x 59x 59x 15x 15x 15x 15x 15x 15x 61x 61x 61x 61x 61x 15x 44x 42x 41x 41x 41x 41x 41x 80x 41x 162x 162x 154x 8x 8x 41x 1x 58x 58x 160x 58x 58x 160x 59x 58x 58x 160x 73x 73x 160x 160x 160x 160x 160x 73x 160x 160x 160x 160x 15x 1x 1x 1x 134x 136x 30x 90x 90x 45x 45x 61x | "use client";
import { fetchApi } from "@/lib/api";
import { useCallback, useEffect, useRef, useState } from "react";
import { Cpu, HardDrive, Loader2, RefreshCw, Users } from "lucide-react";
import { AzureCostEstimatorPanel } from "./_components/AzureCostEstimatorPanel";
import { ClusterResourceBanner } from "./_components/ClusterResourceBanner";
import { ComponentRow } from "./_components/ComponentRow";
import { CostEstimatorPanel } from "./_components/CostEstimatorPanel";
import { CriticalBanner } from "./_components/CriticalBanner";
import { ParticipantTopologySection } from "./_components/ParticipantTopologySection";
import { ResourceSummary } from "./_components/ResourceSummary";
import { SpeTopologySection } from "./_components/SpeTopologySection";
import { TopoComponentCard } from "./_components/TopoComponentCard";
import { T, useT } from "@/lib/i18n/translate";
import {
LAYER_META,
MAX_HISTORY,
REFRESH_INTERVAL,
ROLE_COLORS,
} from "./_components/constants";
import type {
ComponentInfo,
HistoryEntry,
PeakEntry,
Snapshot,
TopologyData,
ViewMode,
} from "./_components/types";
export default function AdminComponentsPage() {
const t = useT("admin");
// Layer view state
const [snapshot, setSnapshot] = useState<Snapshot | null>(null);
const historyRef = useRef<Map<string, HistoryEntry[]>>(new Map());
const [historyVersion, setHistoryVersion] = useState(0);
// Topology view state
const [topology, setTopology] = useState<TopologyData | null>(null);
const peaksRef = useRef<Map<string, PeakEntry>>(new Map());
const [_peakV, setPeakV] = useState(0);
// Shared state
const [viewMode, setViewMode] = useState<ViewMode>("participant");
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [autoRefresh, setAutoRefresh] = useState(true);
const fetchData = useCallback(
async (isManual = false) => {
if (isManual) setRefreshing(true);
try {
if (viewMode === "layer") {
const res = await fetchApi("/api/admin/components");
Iif (!res.ok) return;
const data: Snapshot = await res.json();
setSnapshot(data);
const now = Date.now();
for (const comp of data.components) {
const key = comp.container;
const entries = historyRef.current.get(key) || [];
entries.push({ ts: now, cpu: comp.cpu, mem: comp.mem.usedMB });
while (entries.length > MAX_HISTORY) entries.shift();
historyRef.current.set(key, entries);
}
setHistoryVersion((v) => v + 1);
} else {
const res = await fetchApi("/api/admin/components/topology");
if (!res.ok) return;
const data: TopologyData = await res.json();
setTopology(data);
// Track peak CPU / Memory per container
const now = Date.now();
const cutoff = now - 24 * 60 * 60 * 1000;
const allComps = [
...data.participants.flatMap((p) => p.components),
...data.infrastructure,
];
for (const c of allComps) {
const prev = peaksRef.current.get(c.container);
if (!prev || prev.since < cutoff) {
peaksRef.current.set(c.container, {
maxCpu: c.cpu,
maxMemMB: c.memMB,
since: now,
});
} else {
prev.maxCpu = Math.max(prev.maxCpu, c.cpu);
prev.maxMemMB = Math.max(prev.maxMemMB, c.memMB);
}
}
setPeakV((v) => v + 1);
}
} catch (err) {
console.error("Failed to fetch components:", err);
} finally {
setLoading(false);
if (isManual) setRefreshing(false);
}
},
[viewMode],
);
useEffect(() => {
setLoading(true);
fetchData();
}, [fetchData]);
useEffect(() => {
if (!autoRefresh) return;
const timer = setInterval(() => fetchData(), REFRESH_INTERVAL);
return () => clearInterval(timer);
}, [autoRefresh, fetchData]);
// Layer view helpers
const grouped = (snapshot?.components || []).reduce(
(acc, c) => {
(acc[c.layer] ??= []).push(c);
return acc;
},
{} as Record<string, ComponentInfo[]>,
);
const totalServices = snapshot?.components.length || 0;
const healthyCount =
snapshot?.components.filter((c) => c.status === "healthy").length || 0;
const runningCount =
snapshot?.components.filter((c) => c.status === "running").length || 0;
const totalCpu = snapshot?.components.reduce((s, c) => s + c.cpu, 0) || 0;
// Match the per-row display so the user's manual count of visible values
// adds up to the shown total. Per-row shows "<1" for sub-1 MB (contributes
// 0) and Math.round(usedMB) otherwise — sum the same quantities.
const totalMem =
snapshot?.components.reduce(
(s, c) => s + (c.mem.usedMB < 1 ? 0 : Math.round(c.mem.usedMB)),
0,
) || 0;
void historyVersion;
const timestamp =
viewMode === "layer" ? snapshot?.timestamp : topology?.timestamp;
const participantCount =
viewMode === "participant"
? topology?.summary.totalParticipants ?? 5
: snapshot?.participants.length ?? 5;
return (
<div className="min-h-screen bg-(--bg)">
<div className="max-w-7xl mx-auto px-8 py-10">
{/* ── Page header ── */}
<div className="flex flex-col md:flex-row md:items-end justify-between gap-4 mb-8">
<div>
<h1 className="page-header">{t("EDC Components")}</h1>
<p className="text-(--text-secondary) text-lg mt-1">
{t("Infrastructure health · CPU & memory per service")}
</p>
</div>
<div className="flex items-center gap-2 px-4 py-2 bg-(--success)/10 text-(--success-text) rounded-full border border-(--success)/20 text-sm font-bold tracking-tight">
<span className="w-2 h-2 rounded-full bg-(--success) animate-pulse" />
{t("LIVE MONITORING")}
</div>
</div>
{/* Controls bar */}
<div className="flex items-center justify-between mb-6 flex-wrap gap-2">
<div className="flex items-center gap-4 text-xs text-(--text-secondary)">
{/* View toggle */}
<div className="flex bg-(--surface) p-1 rounded-xl border border-(--border)">
<button
onClick={() => setViewMode("layer")}
className={`px-4 py-1.5 text-xs font-bold rounded-lg transition-all ${
viewMode === "layer"
? "bg-(--surface-card) shadow-xs text-(--accent)"
: "text-(--text-secondary) hover:text-(--text-primary)"
}`}
>
{t("Layer View")}
</button>
<button
onClick={() => setViewMode("participant")}
className={`px-4 py-1.5 text-xs font-bold rounded-lg transition-all ${
viewMode === "participant"
? "bg-(--surface-card) shadow-xs text-(--accent)"
: "text-(--text-secondary) hover:text-(--text-primary)"
}`}
>
{t("Participant View")}
</button>
</div>
{/* Stats summary for layer view */}
{viewMode === "layer" && snapshot && (
<>
<span>{t("{n} services", { n: totalServices })}</span>
<span>·</span>
<span className="text-(--success-text)">
{t("{n} healthy", { n: healthyCount })}
</span>
<span className="text-(--accent)">
{t("{n} running", { n: runningCount })}
</span>
<span>·</span>
<span>
<Cpu size={11} className="inline mr-0.5" />
{t("{value} total", { value: `${totalCpu.toFixed(1)}%` })}
</span>
<span>·</span>
<span>
<HardDrive size={11} className="inline mr-0.5" />
{t("{value} total", {
value:
totalMem > 1024
? `${(totalMem / 1024).toFixed(1)} GB`
: `${Math.round(totalMem)} MB`,
})}
</span>
</>
)}
{/* Stats summary for participant view */}
{viewMode === "participant" && topology && (
<>
<span>
{t("{n} participants", {
n: topology.summary.totalParticipants,
})}
</span>
<span>·</span>
<span>
{t("{n} infra services", { n: topology.summary.totalInfra })}
</span>
{topology.summary.degradedParticipants > 0 && (
<>
<span>·</span>
<span className="text-(--danger-text)">
{t("{n} degraded", {
n: topology.summary.degradedParticipants,
})}
</span>
</>
)}
{topology.metricsShared && (
<>
<span>·</span>
<span
className="italic text-(--text-secondary)"
title={t(
"Participants are logical DIDs on this deployment; they share the same ACA containers. Switch to Layer View for real per-container CPU/MEM from Azure Monitor.",
)}
>
{t("shared infrastructure (see Layer View for metrics)")}
</span>
</>
)}
</>
)}
</div>
<div className="flex items-center gap-3">
<label className="flex items-center gap-1.5 text-xs text-(--text-secondary) cursor-pointer">
<input
type="checkbox"
checked={autoRefresh}
onChange={(e) => setAutoRefresh(e.target.checked)}
className="rounded-sm border-(--border-ui) bg-(--surface-2) text-teal-800 dark:text-teal-300 focus:ring-layer2 w-3.5 h-3.5"
/>
{t("Auto-refresh (30s)")}
</label>
<button
onClick={() => fetchData(true)}
disabled={refreshing}
className="flex items-center gap-1.5 px-3 py-1.5 text-xs border border-(--border) rounded-lg hover:border-layer2 transition-colors disabled:opacity-50"
>
<RefreshCw
size={12}
className={refreshing ? "animate-spin" : ""}
/>
{t("Refresh")}
</button>
</div>
</div>
{loading ? (
<div className="flex items-center gap-2 text-(--text-secondary)">
<Loader2 size={16} className="animate-spin" />
{t("Loading EDC components…")}
</div>
) : viewMode === "participant" ? (
/* ═══════════════════════════════════════════════════════════════
PARTICIPANT VIEW
═══════════════════════════════════════════════════════════════ */
topology && (
<>
{/* Cluster resource banner */}
{topology.clusterMetrics && (
<ClusterResourceBanner metrics={topology.clusterMetrics} />
)}
{/* Critical banner */}
<CriticalBanner
degraded={topology.summary.degradedParticipants}
total={topology.summary.totalParticipants}
participants={topology.participants}
/>
{/* Participant topology sections */}
<div className="space-y-3 mb-8">
<h2 className="font-semibold text-sm flex items-center gap-2 text-(--text-primary) mb-3">
<Users
size={16}
className="text-teal-800 dark:text-teal-300"
/>
{t("Dataspace Participants")}
<span className="text-xs font-normal text-(--text-secondary)">
({topology.participants.length})
</span>
</h2>
{topology.participants.map((p) => (
<ParticipantTopologySection
key={p.id}
participant={p}
peaks={peaksRef.current}
metricsShared={Boolean(topology.metricsShared)}
/>
))}
</div>
{/* Shared infrastructure */}
{topology.infrastructure.length > 0 && (
<div className="mb-8">
<div className="flex items-start justify-between mb-3 flex-wrap gap-2">
<h2 className="font-semibold text-sm flex items-center gap-2 text-(--text-primary)">
<HardDrive size={16} className="text-(--warning-text)" />
{t("Shared Infrastructure")}
<span className="text-xs font-normal text-(--text-secondary)">
({topology.infrastructure.length})
</span>
</h2>
<ResourceSummary
components={topology.infrastructure}
peaks={peaksRef.current}
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2">
{topology.infrastructure.map((c) => (
<TopoComponentCard key={c.container} comp={c} />
))}
</div>
</div>
)}
{/* Docker unavailable */}
{!topology.dockerAvailable && (
<div className="border border-yellow-600/40 bg-yellow-900/20 rounded-xl p-4 text-sm text-(--warning-text)">
<T area="admin" tags={{ b: <strong /> }}>
{
"<b>Docker socket not available.</b> CPU and memory metrics require the Docker socket to be mounted."
}
</T>
</div>
)}
</>
)
) : (
/* ═══════════════════════════════════════════════════════════════
LAYER VIEW (original)
═══════════════════════════════════════════════════════════════ */
<>
{/* Participants */}
{snapshot && snapshot.participants.length > 0 && (
<div className="mb-8">
<h2 className="font-semibold text-sm mb-4 flex items-center gap-2 text-(--text-primary)">
<Users
size={16}
className="text-teal-800 dark:text-teal-300"
/>
{t("Dataspace Participants")}
<span className="text-xs font-normal text-(--text-secondary)">
({snapshot.participants.length})
</span>
</h2>
<div className="overflow-x-auto border border-(--border) rounded-xl">
<table className="w-full text-left">
<thead>
<tr className="border-b border-(--border) bg-(--surface)/60">
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-48">
{t("Participant")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-32">
{t("Role")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary)">
DID
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-28">
{t("State")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-20 text-center">
{t("Profiles")}
</th>
</tr>
</thead>
<tbody>
{snapshot.participants.map((p) => (
<tr
key={p.id}
className="border-b border-(--border) hover:bg-(--surface-2)/40 transition-colors"
>
<td className="py-2.5 px-3">
<div className="font-semibold text-sm text-(--text-primary)">
{p.displayName}
</div>
<div className="text-[11px] text-(--text-secondary)">
{p.organization}
</div>
</td>
<td className="py-2.5 px-3">
<span
className={`text-[10px] font-medium px-2 py-0.5 rounded-full ${
ROLE_COLORS[p.role] ||
"bg-gray-500/20 text-(--text-secondary)"
}`}
>
{p.role}
</span>
</td>
<td className="py-2.5 px-3 font-mono text-[11px] text-(--text-secondary)">
{p.did}
</td>
<td className="py-2.5 px-3">
<span
className={`text-xs font-medium ${
p.state === "CREATED"
? "text-(--success-text)"
: "text-(--warning-text)"
}`}
>
{p.state}
</span>
</td>
<td className="py-2.5 px-3 text-xs text-(--text-primary) text-center">
{p.profileCount}
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
{/* Component tables per layer */}
{["edc-core", "identity", "infrastructure"].map((layer) => {
const items = grouped[layer];
if (!items || items.length === 0) return null;
const meta = LAYER_META[layer];
const LayerIcon = meta.icon;
return (
<div key={layer} className="mb-8">
<h2 className="font-semibold text-sm mb-3 flex items-center gap-2 text-(--text-primary)">
<LayerIcon size={16} className={meta.color} />
{t(meta.label)}
<span className="text-xs font-normal text-(--text-secondary)">
({items.length})
</span>
</h2>
<div className="overflow-x-auto border border-(--border) rounded-xl">
<table className="w-full text-left">
<thead>
<tr className="border-b border-(--border) bg-(--surface)/60">
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-48">
{t("Component")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-28">
{t("Health")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-24">
{t("Uptime")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-40">
{t("CPU (Last 24h)")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-44">
{t("Memory (Last 24h)")}
</th>
<th className="py-2 px-3 text-xs font-medium text-(--text-secondary) w-16">
{t("Mem %")}
</th>
</tr>
</thead>
<tbody>
{items.map((comp) => (
<ComponentRow
key={comp.container}
comp={comp}
history={
historyRef.current.get(comp.container) || []
}
/>
))}
</tbody>
</table>
</div>
</div>
);
})}
{/* Docker unavailable banner — hidden on Azure deployments
(where Docker socket is genuinely not present and metrics come
from Azure Monitor instead). */}
{snapshot &&
!snapshot.dockerAvailable &&
snapshot.metricsSource !== "azure-monitor" &&
snapshot.deploymentTarget !== "azure" && (
<div className="border border-yellow-600/40 bg-yellow-900/20 rounded-xl p-4 text-sm text-(--warning-text)">
<T area="admin" tags={{ b: <strong /> }}>
{
"<b>Docker socket not available.</b> CPU and memory metrics require the Docker socket to be mounted."
}
</T>
</div>
)}
</>
)}
{/* Where the SPEs run: the ACI confidential groups and the Trustee
(ADR-068, #774). Outside the view toggle, so it is fetched once. */}
<SpeTopologySection />
{/* Cost estimates. On Azure, the running deployment first and the
static STACKIT alternative under it, for comparison; elsewhere
only STACKIT. Azure is detected from EITHER endpoint's
deploy-target signal (/api/admin/components snapshot OR the
topology endpoint's metricsShared flag), so the Azure panel
surfaces as soon as any Azure signal is present, e.g. when the
snapshot call raced the Azure Monitor role binding. */}
{(snapshot?.deploymentTarget === "azure" ||
snapshot?.metricsSource === "azure-monitor" ||
topology?.metricsShared === true) && (
<AzureCostEstimatorPanel
liveComponents={snapshot?.components ?? []}
participantCount={participantCount}
/>
)}
<CostEstimatorPanel participantCount={participantCount} />
{/* Timestamp */}
{timestamp && (
<p className="text-[10px] text-(--text-secondary) mt-4">
{t("Last updated: {time}", {
time: new Date(timestamp).toLocaleString(),
})}
</p>
)}
</div>
</div>
);
}
|