Servers and the agent, dashboard (2.1.0): servers, installs, updates, jobs, ports, download page
- Servers: add with a one-time join command, each server's CPU / RAM charts (24 h, 7 days, 90 days, spikes over 85% marked, table view), configuration, PM2 processes, sites, jobs and alerts. - Installs: New install (server chooser with free RAM, CPU and sites), Link existing, FastPanel steps and Proxy done, schedule / emergency update, adopt, uninstall (2FA and the short name). - Updates: one release to many installs (a batch), planned jobs. - Jobs with their reports; Ports & defaults; the public download page that decrypts an export in the browser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo, useRef, useState } from "react";
|
||||
import { fmtDate } from "@/lib/format";
|
||||
|
||||
/** Shared pieces for the servers pages (2.1.0). */
|
||||
|
||||
export type ServerSummary = {
|
||||
id: string; name: string; mode: "church" | "central"; hostname: string | null; agentVersion: string | null;
|
||||
lastSeenAt: string | null; joinedAt: string; removedAt: string | null; notes: string | null; online: boolean;
|
||||
ram: { totalBytes: number; availableBytes: number; usedPercent: number } | null;
|
||||
cpu: { percent: number; load1: number; cores: number } | null;
|
||||
disk: { mount: string; totalBytes: number; usedBytes: number; freeBytes: number }[];
|
||||
versions: { os: string; node: string; postgres: string | null; frpc: string | null; agent: string } | null;
|
||||
frpcRunning: boolean | null;
|
||||
central: { proxyBindAddr: string | null; allowPorts: string | null; frpsRunning: boolean | null } | null;
|
||||
deployments?: number;
|
||||
alerts?: { type: string; level: string; message: string; createdAt: string }[];
|
||||
lastDay?: { cpuAvg: number | null; ramAvg: number | null; cpuPeak: number | null; ramPeak: number | null } | null;
|
||||
};
|
||||
|
||||
export type Deployment = {
|
||||
id: string; serverId: string; customerId: string; installId: string | null; product: string; shortName: string; domain: string;
|
||||
webPort: number; apiPort: number; status: string; version: string | null; adminName: string | null; adminEmail: string | null;
|
||||
liveAt: string | null; createdAt: string;
|
||||
server?: { id: string; name: string }; customer?: { id: string; name: string };
|
||||
install?: { id: string; version: string | null; lastHeartbeatAt: string | null; url: string } | null;
|
||||
};
|
||||
|
||||
export type Job = {
|
||||
id: string; serverId: string; type: string; args: Record<string, unknown>; status: string; notBefore: string; expiresAt: string;
|
||||
scheduled: boolean; emergency: boolean; reason: string | null; batchId: string | null; deliveredAt: string | null; finishedAt: string | null;
|
||||
message: string | null; createdAt: string; deploymentId: string | null;
|
||||
server?: { id: string; name: string }; deployment?: { id: string; shortName: string; domain: string } | null;
|
||||
report?: { status: string; steps: { name: string; startedAt: string; finishedAt: string | null; outcome: string; detail?: string }[]; result: Record<string, unknown>; log: string[]; message?: string } | null;
|
||||
};
|
||||
|
||||
const TONE: Record<string, string> = {
|
||||
green: "bg-green-50 text-green-700 ring-green-600/20",
|
||||
amber: "bg-amber-50 text-amber-800 ring-amber-600/20",
|
||||
red: "bg-red-50 text-red-700 ring-red-600/20",
|
||||
blue: "bg-indigo-50 text-indigo-700 ring-indigo-600/20",
|
||||
grey: "bg-slate-100 text-slate-600 ring-slate-500/20",
|
||||
};
|
||||
|
||||
const STATUS: Record<string, [string, string]> = {
|
||||
// deployments
|
||||
installing: ["Installing", "blue"], waiting_for_proxy: ["Waiting for proxy", "amber"], live: ["Live", "green"], failed: ["Failed", "red"],
|
||||
uninstalling: ["Uninstalling", "amber"], removed: ["Removed", "grey"],
|
||||
// jobs
|
||||
scheduled: ["Waiting its turn", "grey"], queued: ["Due", "blue"], delivered: ["Running", "blue"], succeeded: ["Succeeded", "green"],
|
||||
rolled_back: ["Rolled back", "amber"], refused: ["Refused", "red"], expired: ["Expired", "red"], missed: ["Missed", "red"], cancelled: ["Cancelled", "grey"],
|
||||
// servers
|
||||
online: ["Online", "green"], offline: ["Offline", "red"],
|
||||
};
|
||||
|
||||
/** A status as a label (never colour alone). */
|
||||
export function StatusPill({ status }: { status: string }) {
|
||||
const [label, tone] = STATUS[status] || [status, "grey"];
|
||||
return <span className={`inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium ring-1 ring-inset ${TONE[tone]}`}>{label}</span>;
|
||||
}
|
||||
|
||||
export const pct = (n: number | null | undefined) => (n == null ? "–" : `${Math.round(n)}%`);
|
||||
|
||||
// <input type="datetime-local"> works in the browser's time; the API takes ISO.
|
||||
export const toInput = (d: Date) => new Date(d.getTime() - d.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
|
||||
export const fromInput = (v: string) => (v ? new Date(v).toISOString() : "");
|
||||
|
||||
/**
|
||||
* A single-series line chart of a percentage (0–100) over time, with spikes over `spike`%
|
||||
* marked, a crosshair tooltip and a table view. One axis; the title names the series.
|
||||
*/
|
||||
export function PercentChart({ title, points, spike = 85 }: { title: string; points: { at: string; value: number; peak: number }[]; spike?: number }) {
|
||||
const W = 640, H = 160, L = 34, R = 8, T = 10, B = 22;
|
||||
const [hover, setHover] = useState<number | null>(null);
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
const times = useMemo(() => points.map(p => new Date(p.at).getTime()), [points]);
|
||||
if (points.length < 2) return <div className="card"><h3 className="text-sm font-medium">{title}</h3><p className="mt-2 text-sm text-slate-500">Not enough data yet.</p></div>;
|
||||
const t0 = times[0], t1 = times[times.length - 1] || t0 + 1;
|
||||
const x = (t: number) => L + ((t - t0) / Math.max(1, t1 - t0)) * (W - L - R);
|
||||
const y = (v: number) => T + (1 - Math.min(100, Math.max(0, v)) / 100) * (H - T - B);
|
||||
const path = points.map((p, i) => `${i ? "L" : "M"}${x(times[i]).toFixed(1)},${y(p.value).toFixed(1)}`).join("");
|
||||
const spikes = points.map((p, i) => ({ p, i })).filter(({ p }) => p.peak > spike);
|
||||
const onMove = (e: React.MouseEvent<SVGSVGElement>) => {
|
||||
const r = svgRef.current?.getBoundingClientRect();
|
||||
if (!r) return;
|
||||
const t = t0 + ((((e.clientX - r.left) / r.width) * W - L) / (W - L - R)) * (t1 - t0);
|
||||
let best = 0;
|
||||
for (let i = 1; i < times.length; i++) if (Math.abs(times[i] - t) < Math.abs(times[best] - t)) best = i;
|
||||
setHover(best);
|
||||
};
|
||||
const h = hover != null ? points[hover] : null;
|
||||
return (
|
||||
<div className="card">
|
||||
<div className="flex items-baseline justify-between gap-2">
|
||||
<h3 className="text-sm font-medium">{title}</h3>
|
||||
<span className="text-xs text-slate-500">{spikes.length ? `${spikes.length} spike${spikes.length === 1 ? "" : "s"} over ${spike}%` : `No spikes over ${spike}%`}</span>
|
||||
</div>
|
||||
<div className="relative mt-2">
|
||||
<svg ref={svgRef} viewBox={`0 0 ${W} ${H}`} className="h-40 w-full" role="img" aria-label={`${title}, ${points.length} points`} onMouseMove={onMove} onMouseLeave={() => setHover(null)}>
|
||||
{[0, 50, 100].map(v => (
|
||||
<g key={v}>
|
||||
<line x1={L} x2={W - R} y1={y(v)} y2={y(v)} stroke="#e2e8f0" strokeWidth="1" />
|
||||
<text x={L - 6} y={y(v) + 4} textAnchor="end" className="fill-slate-400 text-[10px]">{v}%</text>
|
||||
</g>
|
||||
))}
|
||||
<line x1={L} x2={W - R} y1={y(spike)} y2={y(spike)} stroke="#f59e0b" strokeWidth="1" strokeDasharray="3 3" />
|
||||
<text x={L} y={H - 6} className="fill-slate-400 text-[10px]">{fmtDate(points[0].at)}</text>
|
||||
<text x={W - R} y={H - 6} textAnchor="end" className="fill-slate-400 text-[10px]">{fmtDate(points[points.length - 1].at)}</text>
|
||||
<path d={path} fill="none" stroke="#4f46e5" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round" />
|
||||
{spikes.map(({ p, i }) => <circle key={i} cx={x(times[i])} cy={y(p.peak)} r="4" fill="#f59e0b" stroke="#fff" strokeWidth="2"><title>{`Spike ${Math.round(p.peak)}% at ${fmtDate(p.at)}`}</title></circle>)}
|
||||
{h && hover != null && (
|
||||
<g>
|
||||
<line x1={x(times[hover])} x2={x(times[hover])} y1={T} y2={H - B} stroke="#94a3b8" strokeWidth="1" />
|
||||
<circle cx={x(times[hover])} cy={y(h.value)} r="4" fill="#4f46e5" stroke="#fff" strokeWidth="2" />
|
||||
</g>
|
||||
)}
|
||||
</svg>
|
||||
{h && hover != null && (
|
||||
<div className="pointer-events-none absolute top-0 rounded-md border border-slate-200 bg-white px-2 py-1 text-xs shadow-sm" style={{ left: `${Math.min(80, (x(times[hover]) / W) * 100)}%` }}>
|
||||
<div className="text-slate-500">{fmtDate(h.at)}</div>
|
||||
<div className="font-medium tabular-nums">{Math.round(h.value)}% (peak {Math.round(h.peak)}%)</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<details className="mt-2 text-xs text-slate-500">
|
||||
<summary className="cursor-pointer">Show as a table</summary>
|
||||
<div className="mt-2 max-h-48 overflow-y-auto">
|
||||
<table className="w-full tabular-nums">
|
||||
<thead><tr className="text-left"><th>Time</th><th className="text-right">Average</th><th className="text-right">Peak</th></tr></thead>
|
||||
<tbody>{points.slice(-200).reverse().map(p => <tr key={p.at}><td>{fmtDate(p.at)}</td><td className="text-right">{Math.round(p.value)}%</td><td className="text-right">{Math.round(p.peak)}%</td></tr>)}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const SUBNAV = [
|
||||
{ href: "/servers", label: "Servers" },
|
||||
{ href: "/servers/installs", label: "Installs" },
|
||||
{ href: "/servers/updates", label: "Updates" },
|
||||
{ href: "/jobs", label: "Jobs" },
|
||||
{ href: "/servers/settings", label: "Ports & defaults" },
|
||||
];
|
||||
|
||||
/** The links between the servers pages. */
|
||||
export function ServersNav({ active }: { active: string }) {
|
||||
return (
|
||||
<nav className="mb-6 flex flex-wrap gap-1 border-b border-slate-200">
|
||||
{SUBNAV.map(n => (
|
||||
<a key={n.href} href={n.href} className={`-mb-px border-b-2 px-3 py-2 text-sm ${active === n.href ? "border-indigo-600 font-medium text-indigo-700" : "border-transparent text-slate-600 hover:text-slate-900"}`}>{n.label}</a>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user