release-2.5.0 (#994)

* feat(sshid) - sshid.io equivalent for termix (#919)

* feat(ssh-id): database schema, migrations and field encryption

Adds ssh_identities, ssh_identity_keys and ssh_identity_ca tables (public keys
stored plaintext for the unauthenticated resolver; CA private key registered
for per-user field encryption), with UNIQUE(user_id), an index on
ssh_identity_keys(identity_id), and idempotent CREATE TABLE migrations.

* feat(ssh-id): backend API — resolver, key management, CA and certificates

Mounts /sshid (nginx route added). Public text/plain authorized_keys resolver
(+ exact /:algo filter, HTML viewer) and CA public-key endpoint; no-store +
noindex headers on every resolver response including early 404s. Authenticated
management: claim/rename/delete handle, add/import/generate/enable/delete keys,
and a per-user CA (create/rotate/delete) with pure-Node OpenSSH certificate
issuance. Audit logging on all mutations; UNIQUE races map to a precise 409.
Unit tests for key parsing and certificate signing (ssh-keygen-validated).

* feat(ssh-id): frontend panel, API client and i18n

SSH ID panel wired into the app rail and AppShell: claim handle, resolver URL +
curl one-liner, key list, generate, paste/import, CA enable/rotate/remove with
server trust command, and per-key certificate issuance. API client re-exported
through main-axios.ts; all strings i18n'd.

* style(ssh-id): align panel and resolver page with Termix theme

- Rebuild the SSH ID sidebar panel with the theme's square components
  (SectionCard / SettingRow / FakeSwitch) instead of rounded ad-hoc cards;
  use accent-brand and destructive tokens rather than raw red/green.
- Fix panel scrolling: move overflow to a block scroll container so the
  cards keep their natural height instead of being clipped.
- Restyle the public resolver HTML page (/sshid/u/:handle) to the Termix
  dark theme: square corners, #18181b/#303032 palette, #f59145 accent,
  uppercase section labels.
- Tidy copy: 'Save To Credentials' label, drop the redundant generate intro,
  and correct the generate tooltip (the key is stored when saving to vault).

* feat: rename to Termix ID, improve UI, backend inconsistencies, and general bug fixes

---------

Co-authored-by: LukeGus <bugattiguy527@gmail.com>

* ci(deps): bump actions/checkout from 6 to 7 in the github-actions group (#922)

Bumps the github-actions group with 1 update: [actions/checkout](https://github.com/actions/checkout).


Updates `actions/checkout` from 6 to 7
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump the dev-patch-updates group with 11 updates (#923)

Bumps the dev-patch-updates group with 11 updates:

| Package | From | To |
| --- | --- | --- |
| [@codemirror/search](https://github.com/codemirror/search) | `6.7.0` | `6.7.1` |
| [@codemirror/view](https://github.com/codemirror/view) | `6.43.0` | `6.43.1` |
| [@tailwindcss/vite](https://github.com/tailwindlabs/tailwindcss/tree/HEAD/packages/@tailwindcss-vite) | `4.3.0` | `4.3.1` |
| [@vitest/coverage-v8](https://github.com/vitest-dev/vitest/tree/HEAD/packages/coverage-v8) | `4.1.8` | `4.1.9` |
| [@vitest/ui](https://github.com/vitest-dev/vitest/tree/HEAD/packages/ui) | `4.1.8` | `4.1.9` |
| [eslint-plugin-react-refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) | `0.5.2` | `0.5.3` |
| [lint-staged](https://github.com/lint-staged/lint-staged) | `17.0.7` | `17.0.8` |
| [prettier](https://github.com/prettier/prettier) | `3.8.3` | `3.8.4` |
| [sharp](https://github.com/lovell/sharp) | `0.35.1` | `0.35.2` |
| [tailwindcss](https://github.com/tailwindlabs/tailwindcss/tree/HEAD/packages/tailwindcss) | `4.3.0` | `4.3.1` |
| [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest) | `4.1.8` | `4.1.9` |


Updates `@codemirror/search` from 6.7.0 to 6.7.1
- [Changelog](https://github.com/codemirror/search/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codemirror/search/commits)

Updates `@codemirror/view` from 6.43.0 to 6.43.1
- [Changelog](https://github.com/codemirror/view/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codemirror/view/commits)

Updates `@tailwindcss/vite` from 4.3.0 to 4.3.1
- [Release notes](https://github.com/tailwindlabs/tailwindcss/releases)
- [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/tailwindlabs/tailwindcss/commits/v4.3.1/packages/@tailwindcss-vite)

Updates `@vitest/coverage-v8` from 4.1.8 to 4.1.9
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Changelog](https://github.com/vitest-dev/vitest/blob/main/docs/releases.md)
- [Commits](https://github.com/vitest-dev/vitest/commits/v4.1.9/packages/coverage-v8)

Updates `@vitest/ui` from 4.1.8 to 4.1.9
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Changelog](https://github.com/vitest-dev/vitest/blob/main/docs/releases.md)
- [Commits](https://github.com/vitest-dev/vitest/commits/v4.1.9/packages/ui)

Updates `eslint-plugin-react-refresh` from 0.5.2 to 0.5.3
- [Release notes](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/releases)
- [Changelog](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/compare/v0.5.2...v0.5.3)

Updates `lint-staged` from 17.0.7 to 17.0.8
- [Release notes](https://github.com/lint-staged/lint-staged/releases)
- [Changelog](https://github.com/lint-staged/lint-staged/blob/main/CHANGELOG.md)
- [Commits](https://github.com/lint-staged/lint-staged/compare/v17.0.7...v17.0.8)

Updates `prettier` from 3.8.3 to 3.8.4
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/3.8.3...3.8.4)

Updates `sharp` from 0.35.1 to 0.35.2
- [Release notes](https://github.com/lovell/sharp/releases)
- [Commits](https://github.com/lovell/sharp/compare/v0.35.1...v0.35.2)

Updates `tailwindcss` from 4.3.0 to 4.3.1
- [Release notes](https://github.com/tailwindlabs/tailwindcss/releases)
- [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/tailwindlabs/tailwindcss/commits/v4.3.1/packages/tailwindcss)

Updates `vitest` from 4.1.8 to 4.1.9
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Changelog](https://github.com/vitest-dev/vitest/blob/main/docs/releases.md)
- [Commits](https://github.com/vitest-dev/vitest/commits/v4.1.9/packages/vitest)

---
updated-dependencies:
- dependency-name: "@codemirror/search"
  dependency-version: 6.7.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: "@codemirror/view"
  dependency-version: 6.43.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: "@tailwindcss/vite"
  dependency-version: 4.3.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: "@vitest/coverage-v8"
  dependency-version: 4.1.9
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: "@vitest/ui"
  dependency-version: 4.1.9
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: eslint-plugin-react-refresh
  dependency-version: 0.5.3
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: lint-staged
  dependency-version: 17.0.8
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: prettier
  dependency-version: 3.8.4
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: sharp
  dependency-version: 0.35.2
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: tailwindcss
  dependency-version: 4.3.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
- dependency-name: vitest
  dependency-version: 4.1.9
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-patch-updates
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump nanoid in the prod-patch-updates group (#925)

Bumps the prod-patch-updates group with 1 update: [nanoid](https://github.com/ai/nanoid).


Updates `nanoid` from 5.1.11 to 5.1.15
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ai/nanoid/compare/5.1.11...5.1.15)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-version: 5.1.15
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: prod-patch-updates
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump the major-updates group with 5 updates (#926)

Bumps the major-updates group with 5 updates:

| Package | From | To |
| --- | --- | --- |
| [js-yaml](https://github.com/nodeca/js-yaml) | `4.2.0` | `5.0.0` |
| [@eslint/js](https://github.com/eslint/eslint/tree/HEAD/packages/js) | `9.39.4` | `10.0.1` |
| [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `25.9.2` | `26.0.0` |
| [concurrently](https://github.com/open-cli-tools/concurrently) | `9.2.1` | `10.0.3` |
| [eslint](https://github.com/eslint/eslint) | `9.39.4` | `10.5.0` |


Updates `js-yaml` from 4.2.0 to 5.0.0
- [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/4.2.0...5.0.0)

Updates `@eslint/js` from 9.39.4 to 10.0.1
- [Release notes](https://github.com/eslint/eslint/releases)
- [Commits](https://github.com/eslint/eslint/commits/v10.0.1/packages/js)

Updates `@types/node` from 25.9.2 to 26.0.0
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Updates `concurrently` from 9.2.1 to 10.0.3
- [Release notes](https://github.com/open-cli-tools/concurrently/releases)
- [Commits](https://github.com/open-cli-tools/concurrently/compare/v9.2.1...v10.0.3)

Updates `eslint` from 9.39.4 to 10.5.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Commits](https://github.com/eslint/eslint/compare/v9.39.4...v10.5.0)

---
updated-dependencies:
- dependency-name: js-yaml
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: major-updates
- dependency-name: "@eslint/js"
  dependency-version: 10.0.1
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: major-updates
- dependency-name: "@types/node"
  dependency-version: 26.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: major-updates
- dependency-name: concurrently
  dependency-version: 10.0.3
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: major-updates
- dependency-name: eslint
  dependency-version: 10.5.0
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: major-updates
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat(ssh): add HashiCorp Vault SSH signer authentication

* fix: small fixes to vault feature to align with Termix codebase

* chore: add view docs links for vault/termix id

* fix: file upload fails with 400 and missing schema migrations on upgrade (#929)

Two bugs introduced in v2.4.1:

1. uploadFileStream uses fileManagerApi.post() which triggers axios's
   transformRequest to JSON-serialize the FormData because the instance
   default Content-Type is application/json. Change to postForm() which
   sets Content-Type: multipart/form-data so the browser XHR sends the
   correct multipart body with boundary.

2. Two schema items added to schema.ts were not included in migrateSchema()
   in db/index.ts, causing 500 errors on existing installations upgrading
   from v2.4.0:
   - user_preferences.status_color_scheme (no such column)
   - dashboard_service_links table (no such table)

Fixes #928

Co-authored-by: sash <sash@fominykh.io>

* fix: support PuTTY PPK ssh keys (#930)

* fix: chunk large file manager uploads (#932)

* fix: route dashboard hosts by protocol (#934)

* fix: resolve tunnel endpoints reliably (#935)

* Fix Electron OIDC browser auth failures (#936)

* Allow RDP connections without stored credentials (#937)

* Sync role credential shares for OIDC users (#938)

* Fix terminal link dialog layering (#940)

* Confirm large files before opening editor (#942)

* Confirm closing active host connections (#943)

* Preserve file path case in file manager UI (#941)

* fix: preserve unicode guacamole tokens (#933)

* Persist VNC authentication settings (#944)

* Fix Guacamole websocket base path (#946)

* Promote file manager terminals to tabs (#939)

* Guard Guacamole disconnect during startup (#945)

* chore: increment ver

* feat: bitwarden ssh agent integration

* feat: serial connections support

* fix: various small bug fixes

* feat: open all sessions in a folder and terminal custom theme color support

* feat: cross host file manager clipboard and several small bug fixes

* feat: tailscale/wireguard support and added a new status state for when backend is checking status

* feat: grafana like server stats history, new alert system, ntfy/webhook support

* feat: new grid and widget based homepage function

* feat: new donate button in dashboard

* fix: alert ui incorrectly using termix css and fixed issue with alert system not loading

* chore: fix ci checks (#966)

* Fix dashboard service link creation (#950)

* Fix jump host SOCKS5 proxy selection (#951)

* Fix jump host SOCKS5 proxy selection

* fix: type jump host socks proxy config

* Fix tmux detection path handling (#949)

* Support GUACD_URL environment config (#952)

* Retry autostart tunnel host fetches (#953)

* Retry autostart tunnel host fetches

* chore: format tunnel route

* Fix PUID html ownership in Docker entrypoint (#954)

* feat: allow custom tunnel endpoints (#977)

* fix: skip metrics start for non-ssh hosts (#976)

* Fix Proxmox import auth fallback (#956)

* Fix Proxmox import auth fallback

* chore: format proxmox import auth

* Fix SSH heading syntax highlighting (#955)

* Fix SSH heading syntax highlighting

* chore: format terminal highlighter

* Initialize auth before fullscreen terminal routes (#957)

* Add WebAuthn passkey authentication (#959)

* chore: add Biome tooling (#965)

* chore: add biome tooling

* chore: support tailwind syntax in biome

* Fix VNC required argument handshake (#968)

* Prioritize host results in command palette search (#969)

* Prevent sidebar host hover layout shift (#970)

* Add terminal font zoom with mouse wheel (#971)

* Add host temperature metrics card (#972)

* Make file downloads reliable in desktop app (#973)

* Add app rail hover expansion setting (#974)

* fix: use correct translation key for nav.close (#964)

* fix(tunnel): skip endpoint credential validation for direct tunnels (#963)

* fix: SSH port connection bug (#975)

* fix: chunked upload for files >=1.5GB to bypass browser ArrayBuffer limit (#948)

* feat: support SSH agent auth across SSH features (#960)

* feat: add Podman container runtime support (#958)

* chore: update readme and release notes

* fix: stabilize Windows app icon (#978)

* Add safe host sharing export (#979)

* Add external editor support for file manager (#985)

* Rework SSH credential password handling (#984)

* Support password fallback for SSH key credentials

* Complete SSH credential password fallback

* Fix runtime base path for auth callbacks (#982)

* Fix TUI terminal output highlighting (#983)

Co-authored-by: LukeGus <bugattiguy527@gmail.com>

* Add app fullscreen mode (#993)

* Fix host metrics startup polling (#986)

* chore: update release notes

* fix: line chart text overlap

* chore: update RELEASE_NOTES.md

* chore: add donation goal to readme

* chore: update readme

* fix: hide full-screen button in electron app

* fix: failed unit tests

* chore: lint, format, and bump version to 2.5.0

* chore: remove timeout from crowdin translate

* chore: sync Crowdin translations for 2.5.0

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: DivByZero <mr.oplus@yahoo.fr>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: devdanetra <46488477+devdanetra@users.noreply.github.com>
Co-authored-by: Aleksandr Fominykh <neoformalex@users.noreply.github.com>
Co-authored-by: sash <sash@fominykh.io>
Co-authored-by: ZacharyZcR <zacharyzcr1984@gmail.com>
This commit is contained in:
Luke Gustafson
2026-06-29 13:28:26 -05:00
committed by GitHub
co-authored by dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> sash LukeGus DivByZero devdanetra Aleksandr Fominykh ZacharyZcR
parent fd27a366d0
commit 9de904dd4c
348 changed files with 125184 additions and 76537 deletions
+12 -13
View File
@@ -361,24 +361,21 @@ function HostMetricsInner({
setViewerSessionId(result.viewerSessionId);
}
// Poll until first metrics arrive. The backend's initial SSH collection
// can take up to ~60s (queue timeout), so we wait up to 90s total.
let retry = 0;
let data: ServerMetrics | null = null;
const maxRetries = 15;
const maxRetries = 30;
while (retry < maxRetries && !cancelled) {
try {
data = await getServerMetricsById(currentHostConfig.id);
break;
} catch (error) {
retry++;
if (retry === 1) {
await new Promise((r) =>
setTimeout(r, totpVerified ? 3000 : 5000),
);
} else if (retry < maxRetries && !cancelled) {
await new Promise((r) => setTimeout(r, 2000));
} else {
throw error;
}
if (data) break;
} catch {
// non-404 error — keep retrying
}
retry++;
if (retry < maxRetries && !cancelled) {
await new Promise((r) => setTimeout(r, 3000));
}
}
if (cancelled) return;
@@ -390,6 +387,8 @@ function HostMetricsInner({
setIsLoadingMetrics(false);
logServerActivity();
}
} else {
throw new Error(t("hostMetrics.connectionFailed"));
}
pollingId = window.setInterval(async () => {
@@ -0,0 +1,222 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { LineChart, type LineChartSeries } from "@/components/charts/LineChart";
import {
getMetricsHistory,
type MetricsHistoryRow,
} from "@/api/host-metrics-api";
export type HistoryRange = "1h" | "6h" | "24h" | "7d" | "30d";
interface MetricsHistorySectionProps {
hostId: number;
timeRange: HistoryRange;
}
function computeNetRates(rows: MetricsHistoryRow[]): {
rxRates: Array<number | null>;
txRates: Array<number | null>;
} {
const rxRates: Array<number | null> = [];
const txRates: Array<number | null> = [];
for (let i = 0; i < rows.length; i++) {
if (i === 0) {
rxRates.push(null);
txRates.push(null);
continue;
}
const prev = rows[i - 1];
const curr = rows[i];
const dtSec =
(new Date(curr.ts).getTime() - new Date(prev.ts).getTime()) / 1000;
if (
dtSec < 0.5 ||
prev.net_rx_bytes == null ||
curr.net_rx_bytes == null ||
prev.net_tx_bytes == null ||
curr.net_tx_bytes == null
) {
rxRates.push(null);
txRates.push(null);
continue;
}
const rxDelta = curr.net_rx_bytes - prev.net_rx_bytes;
const txDelta = curr.net_tx_bytes - prev.net_tx_bytes;
rxRates.push(rxDelta < 0 ? null : rxDelta / dtSec);
txRates.push(txDelta < 0 ? null : txDelta / dtSec);
}
return { rxRates, txRates };
}
function formatBytes(bps: number): string {
if (bps >= 1024 * 1024) return `${(bps / 1024 / 1024).toFixed(1)} MB/s`;
if (bps >= 1024) return `${(bps / 1024).toFixed(1)} KB/s`;
return `${Math.round(bps)} B/s`;
}
function maxOrZero(arr: Array<number | null>): number {
return arr.reduce<number>((m, v) => (v != null && v > m ? v : m), 0);
}
export function MetricsHistorySection({
hostId,
timeRange,
}: MetricsHistorySectionProps) {
const { t } = useTranslation();
const [rows, setRows] = useState<MetricsHistoryRow[] | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
setLoading(true);
setError(null);
getMetricsHistory(hostId, { range: timeRange })
.then((res) => {
if (!cancelled) {
setRows(res.rows);
setLoading(false);
}
})
.catch((err) => {
if (!cancelled) {
setError(
err instanceof Error ? err.message : "Failed to load history",
);
setLoading(false);
}
});
return () => {
cancelled = true;
};
}, [hostId, timeRange]);
const timestamps = rows?.map((r) => r.ts) ?? [];
const cpuSeries: LineChartSeries = {
key: "cpu",
label: t("hostMetrics.cpuUsage"),
color: "var(--accent-brand)",
data: rows?.map((r) => r.cpu_percent) ?? [],
};
const memSeries: LineChartSeries = {
key: "mem",
label: t("hostMetrics.memoryUsage"),
color: "var(--chart-3)",
data: rows?.map((r) => r.mem_percent) ?? [],
};
const diskSeries: LineChartSeries = {
key: "disk",
label: t("hostMetrics.diskUsage"),
color: "var(--chart-4)",
data: rows?.map((r) => r.disk_percent) ?? [],
};
const { rxRates, txRates } = rows
? computeNetRates(rows)
: { rxRates: [], txRates: [] };
const netMax = Math.max(maxOrZero(rxRates), maxOrZero(txRates), 1024);
const rxSeries: LineChartSeries = {
key: "rx",
label: t("metricsHistory.download"),
color: "var(--chart-2)",
data: rxRates,
};
const txSeries: LineChartSeries = {
key: "tx",
label: t("metricsHistory.upload"),
color: "var(--chart-5)",
data: txRates,
};
const hasData = rows !== null && rows.length > 0;
const hasNetData = rxRates.some((v) => v !== null);
if (loading) {
return (
<div className="flex flex-col gap-4 px-3 pb-3">
{["cpu", "mem", "disk", "net"].map((k) => (
<div key={k} className="border border-border bg-card p-4">
<div className="mb-3 h-3 w-24 animate-pulse rounded bg-muted" />
<div className="h-40 animate-pulse rounded bg-muted" />
</div>
))}
</div>
);
}
if (error) {
return (
<div className="mx-3 flex h-40 items-center justify-center border border-border bg-card text-sm text-destructive">
{error}
</div>
);
}
if (!hasData) {
return (
<div className="mx-3 flex h-40 items-center justify-center border border-border bg-card text-sm text-muted-foreground">
{t("metricsHistory.noData")}
</div>
);
}
return (
<div className="flex flex-col gap-4 px-3 pb-3">
<div className="border border-border bg-card p-4">
<div className="mb-3 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground">
{t("hostMetrics.cpuUsage")}
</div>
<LineChart
series={[cpuSeries]}
timestamps={timestamps}
domain={[0, 100]}
yFormatter={(v) => `${v.toFixed(0)}%`}
height={160}
/>
</div>
<div className="border border-border bg-card p-4">
<div className="mb-3 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground">
{t("hostMetrics.memoryUsage")}
</div>
<LineChart
series={[memSeries]}
timestamps={timestamps}
domain={[0, 100]}
yFormatter={(v) => `${v.toFixed(0)}%`}
height={160}
/>
</div>
<div className="border border-border bg-card p-4">
<div className="mb-3 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground">
{t("hostMetrics.diskUsage")}
</div>
<LineChart
series={[diskSeries]}
timestamps={timestamps}
domain={[0, 100]}
yFormatter={(v) => `${v.toFixed(0)}%`}
height={160}
/>
</div>
<div className="border border-border bg-card p-4">
<div className="mb-3 text-[10px] font-semibold uppercase tracking-widest text-muted-foreground">
{t("metricsHistory.network")}
</div>
{hasNetData ? (
<LineChart
series={[rxSeries, txSeries]}
timestamps={timestamps}
domain={[0, netMax]}
yFormatter={formatBytes}
height={160}
/>
) : (
<div className="flex h-40 items-center justify-center text-sm text-muted-foreground">
{t("metricsHistory.noData")}
</div>
)}
</div>
</div>
);
}
@@ -0,0 +1,34 @@
import { cn } from "@/lib/utils";
import { useTranslation } from "react-i18next";
export type HistoryTab = "live" | "1h" | "6h" | "24h" | "7d";
const TABS: HistoryTab[] = ["live", "1h", "6h", "24h", "7d"];
export function CardTimeTabs({
value,
onChange,
}: {
value: HistoryTab;
onChange: (tab: HistoryTab) => void;
}) {
const { t } = useTranslation();
return (
<div className="flex items-center gap-0.5">
{TABS.map((tab) => (
<button
key={tab}
onClick={() => onChange(tab)}
className={cn(
"px-2 py-0.5 text-[10px] font-semibold uppercase tracking-widest transition-colors border",
value === tab
? "border-accent-brand bg-accent-brand/10 text-accent-brand"
: "border-transparent text-muted-foreground hover:text-foreground",
)}
>
{tab === "live" ? t("hostMetrics.tabLive") : tab}
</button>
))}
</div>
);
}
+103 -23
View File
@@ -1,51 +1,131 @@
import { useState, useEffect } from "react";
import { Cpu } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { ServerMetrics } from "@/main-axios";
import { RadialGauge, Sparkline, MiniStat } from "@/components/charts";
import { MetricCard } from "./MetricCard";
import { LineChart, type LineChartSeries } from "@/components/charts/LineChart";
import {
getMetricsHistory,
type MetricsHistoryRow,
} from "@/api/host-metrics-api";
import { CardTimeTabs, type HistoryTab } from "./CardTimeTabs";
function computeChartData(rows: MetricsHistoryRow[]) {
return {
data: rows.map((r) => r.cpu_percent),
timestamps: rows.map((r) => r.ts),
};
}
export function CpuCard({
metrics,
history,
hostId,
}: {
metrics: ServerMetrics | null;
history: number[];
hostId: number | null;
}) {
const { t } = useTranslation();
const [activeTab, setActiveTab] = useState<HistoryTab>("live");
const [rows, setRows] = useState<MetricsHistoryRow[] | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (activeTab === "live" || hostId == null) return;
let cancelled = false;
setLoading(true);
setRows(null);
getMetricsHistory(hostId, { range: activeTab })
.then((res) => {
if (!cancelled) {
setRows(res.rows);
setLoading(false);
}
})
.catch(() => {
if (!cancelled) setLoading(false);
});
return () => {
cancelled = true;
};
}, [activeTab, hostId]);
const percent = metrics?.cpu?.percent ?? null;
const cores = metrics?.cpu?.cores ?? null;
const load = metrics?.cpu?.load ?? null;
const series: LineChartSeries[] = [
{
key: "cpu",
label: t("hostMetrics.cpuUsage"),
color: "var(--accent-brand)",
data: rows?.map((r) => r.cpu_percent) ?? [],
},
];
const timestamps = rows?.map((r) => r.ts) ?? [];
return (
<MetricCard
title={t("hostMetrics.cpuUsage")}
icon={<Cpu className="size-3.5" />}
action={
hostId != null ? (
<CardTimeTabs value={activeTab} onChange={setActiveTab} />
) : undefined
}
>
<div className="flex h-full flex-col gap-3">
<div className="flex items-center gap-4">
<RadialGauge
value={percent}
caption={
cores !== null
? t("hostMetrics.cpuCores", { count: cores })
: undefined
}
/>
<div className="flex min-w-0 flex-1 flex-col gap-2">
{load && (
<div className="grid grid-cols-3 gap-2">
<MiniStat caption="1m" value={load[0].toFixed(2)} />
<MiniStat caption="5m" value={load[1].toFixed(2)} />
<MiniStat caption="15m" value={load[2].toFixed(2)} />
<div className="flex flex-col gap-3">
{activeTab === "live" && (
<div className="flex items-center gap-4">
<RadialGauge
value={percent}
caption={
cores !== null
? t("hostMetrics.cpuCores", { count: cores })
: undefined
}
/>
<div className="flex min-w-0 flex-1 flex-col gap-2">
{load && (
<div className="grid grid-cols-3 gap-2">
<MiniStat caption="1m" value={load[0].toFixed(2)} />
<MiniStat caption="5m" value={load[1].toFixed(2)} />
<MiniStat caption="15m" value={load[2].toFixed(2)} />
</div>
)}
<Sparkline
data={[...history, percent ?? 0]}
domain={[0, 100]}
height={48}
/>
</div>
</div>
)}
{activeTab !== "live" && (
<>
{loading && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("common.loading")}
</div>
)}
<Sparkline
data={[...history, percent ?? 0]}
domain={[0, 100]}
height={48}
/>
</div>
</div>
{!loading && rows !== null && rows.length === 0 && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("metricsHistory.noData")}
</div>
)}
{!loading && rows !== null && rows.length > 0 && (
<LineChart
series={series}
timestamps={timestamps}
domain={[0, 100]}
yFormatter={(v) => `${v.toFixed(0)}%`}
height={160}
/>
)}
</>
)}
</div>
</MetricCard>
);
+95 -20
View File
@@ -1,50 +1,125 @@
import { useState, useEffect } from "react";
import { HardDrive } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { ServerMetrics } from "@/main-axios";
import { RadialGauge, Sparkline, MiniStat } from "@/components/charts";
import { MetricCard } from "./MetricCard";
import { LineChart, type LineChartSeries } from "@/components/charts/LineChart";
import {
getMetricsHistory,
type MetricsHistoryRow,
} from "@/api/host-metrics-api";
import { CardTimeTabs, type HistoryTab } from "./CardTimeTabs";
export function DiskCard({
metrics,
history,
hostId,
}: {
metrics: ServerMetrics | null;
history: number[];
hostId: number | null;
}) {
const { t } = useTranslation();
const [activeTab, setActiveTab] = useState<HistoryTab>("live");
const [rows, setRows] = useState<MetricsHistoryRow[] | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (activeTab === "live" || hostId == null) return;
let cancelled = false;
setLoading(true);
setRows(null);
getMetricsHistory(hostId, { range: activeTab })
.then((res) => {
if (!cancelled) {
setRows(res.rows);
setLoading(false);
}
})
.catch(() => {
if (!cancelled) setLoading(false);
});
return () => {
cancelled = true;
};
}, [activeTab, hostId]);
const percent = metrics?.disk?.percent ?? null;
const usedHuman = metrics?.disk?.usedHuman ?? null;
const totalHuman = metrics?.disk?.totalHuman ?? null;
const availableHuman = metrics?.disk?.availableHuman ?? null;
const series: LineChartSeries[] = [
{
key: "disk",
label: t("hostMetrics.diskUsage"),
color: "var(--chart-4)",
data: rows?.map((r) => r.disk_percent) ?? [],
},
];
const timestamps = rows?.map((r) => r.ts) ?? [];
return (
<MetricCard
title={t("hostMetrics.diskUsage")}
icon={<HardDrive className="size-3.5" />}
action={
hostId != null ? (
<CardTimeTabs value={activeTab} onChange={setActiveTab} />
) : undefined
}
>
<div className="flex h-full flex-col gap-3">
<div className="flex items-center gap-4">
<RadialGauge value={percent} />
<div className="flex min-w-0 flex-1 flex-col gap-2">
<div className="grid grid-cols-2 gap-2">
<MiniStat
caption={t("hostMetrics.disk")}
value={
usedHuman && totalHuman ? `${usedHuman}/${totalHuman}` : "N/A"
}
/>
<MiniStat
caption={t("hostMetrics.available")}
value={availableHuman ?? "N/A"}
<div className="flex flex-col gap-3">
{activeTab === "live" && (
<div className="flex items-center gap-4">
<RadialGauge value={percent} />
<div className="flex min-w-0 flex-1 flex-col gap-2">
<div className="grid grid-cols-2 gap-2">
<MiniStat
caption={t("hostMetrics.disk")}
value={
usedHuman && totalHuman
? `${usedHuman}/${totalHuman}`
: "N/A"
}
/>
<MiniStat
caption={t("hostMetrics.available")}
value={availableHuman ?? "N/A"}
/>
</div>
<Sparkline
data={[...history, percent ?? 0]}
domain={[0, 100]}
height={48}
/>
</div>
<Sparkline
data={[...history, percent ?? 0]}
domain={[0, 100]}
height={48}
/>
</div>
</div>
)}
{activeTab !== "live" && (
<>
{loading && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("common.loading")}
</div>
)}
{!loading && rows !== null && rows.length === 0 && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("metricsHistory.noData")}
</div>
)}
{!loading && rows !== null && rows.length > 0 && (
<LineChart
series={series}
timestamps={timestamps}
domain={[0, 100]}
yFormatter={(v) => `${v.toFixed(0)}%`}
height={160}
/>
)}
</>
)}
</div>
</MetricCard>
);
@@ -1,53 +1,126 @@
import { useState, useEffect } from "react";
import { MemoryStick } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { ServerMetrics } from "@/main-axios";
import { RadialGauge, Sparkline, MiniStat } from "@/components/charts";
import { MetricCard } from "./MetricCard";
import { LineChart, type LineChartSeries } from "@/components/charts/LineChart";
import {
getMetricsHistory,
type MetricsHistoryRow,
} from "@/api/host-metrics-api";
import { CardTimeTabs, type HistoryTab } from "./CardTimeTabs";
export function MemoryCard({
metrics,
history,
hostId,
}: {
metrics: ServerMetrics | null;
history: number[];
hostId: number | null;
}) {
const { t } = useTranslation();
const [activeTab, setActiveTab] = useState<HistoryTab>("live");
const [rows, setRows] = useState<MetricsHistoryRow[] | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (activeTab === "live" || hostId == null) return;
let cancelled = false;
setLoading(true);
setRows(null);
getMetricsHistory(hostId, { range: activeTab })
.then((res) => {
if (!cancelled) {
setRows(res.rows);
setLoading(false);
}
})
.catch(() => {
if (!cancelled) setLoading(false);
});
return () => {
cancelled = true;
};
}, [activeTab, hostId]);
const percent = metrics?.memory?.percent ?? null;
const usedGiB = metrics?.memory?.usedGiB ?? null;
const totalGiB = metrics?.memory?.totalGiB ?? null;
const freeGiB =
usedGiB !== null && totalGiB !== null ? totalGiB - usedGiB : null;
const series: LineChartSeries[] = [
{
key: "mem",
label: t("hostMetrics.memoryUsage"),
color: "var(--chart-3)",
data: rows?.map((r) => r.mem_percent) ?? [],
},
];
const timestamps = rows?.map((r) => r.ts) ?? [];
return (
<MetricCard
title={t("hostMetrics.memoryUsage")}
icon={<MemoryStick className="size-3.5" />}
action={
hostId != null ? (
<CardTimeTabs value={activeTab} onChange={setActiveTab} />
) : undefined
}
>
<div className="flex h-full flex-col gap-3">
<div className="flex items-center gap-4">
<RadialGauge value={percent} />
<div className="flex min-w-0 flex-1 flex-col gap-2">
<div className="grid grid-cols-2 gap-2">
<MiniStat
caption={t("hostMetrics.memory")}
value={
usedGiB !== null && totalGiB !== null
? `${usedGiB.toFixed(1)}/${totalGiB.toFixed(1)}G`
: "N/A"
}
/>
<MiniStat
caption={t("hostMetrics.free")}
value={freeGiB !== null ? `${freeGiB.toFixed(1)}G` : "N/A"}
<div className="flex flex-col gap-3">
{activeTab === "live" && (
<div className="flex items-center gap-4">
<RadialGauge value={percent} />
<div className="flex min-w-0 flex-1 flex-col gap-2">
<div className="grid grid-cols-2 gap-2">
<MiniStat
caption={t("hostMetrics.memory")}
value={
usedGiB !== null && totalGiB !== null
? `${usedGiB.toFixed(1)}/${totalGiB.toFixed(1)}G`
: "N/A"
}
/>
<MiniStat
caption={t("hostMetrics.free")}
value={freeGiB !== null ? `${freeGiB.toFixed(1)}G` : "N/A"}
/>
</div>
<Sparkline
data={[...history, percent ?? 0]}
domain={[0, 100]}
height={48}
/>
</div>
<Sparkline
data={[...history, percent ?? 0]}
domain={[0, 100]}
height={48}
/>
</div>
</div>
)}
{activeTab !== "live" && (
<>
{loading && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("common.loading")}
</div>
)}
{!loading && rows !== null && rows.length === 0 && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("metricsHistory.noData")}
</div>
)}
{!loading && rows !== null && rows.length > 0 && (
<LineChart
series={series}
timestamps={timestamps}
domain={[0, 100]}
yFormatter={(v) => `${v.toFixed(0)}%`}
height={160}
/>
)}
</>
)}
</div>
</MetricCard>
);
@@ -1,7 +1,14 @@
import { useState, useEffect } from "react";
import { Cable, Container, Network, Wifi, WifiOff } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { ServerMetrics } from "@/main-axios";
import { MetricCard } from "./MetricCard";
import { LineChart, type LineChartSeries } from "@/components/charts/LineChart";
import {
getMetricsHistory,
type MetricsHistoryRow,
} from "@/api/host-metrics-api";
import { CardTimeTabs, type HistoryTab } from "./CardTimeTabs";
function ifaceIcon(name: string) {
if (/^(wl|wlan|wifi|ath)/.test(name))
@@ -13,53 +20,179 @@ function ifaceIcon(name: string) {
return <Network className="size-3 text-muted-foreground/60" />;
}
export function NetworkCard({ metrics }: { metrics: ServerMetrics | null }) {
function computeNetRates(rows: MetricsHistoryRow[]): {
rxRates: Array<number | null>;
txRates: Array<number | null>;
} {
const rxRates: Array<number | null> = [];
const txRates: Array<number | null> = [];
for (let i = 0; i < rows.length; i++) {
if (i === 0) {
rxRates.push(null);
txRates.push(null);
continue;
}
const prev = rows[i - 1];
const curr = rows[i];
const dtSec =
(new Date(curr.ts).getTime() - new Date(prev.ts).getTime()) / 1000;
if (
dtSec < 0.5 ||
prev.net_rx_bytes == null ||
curr.net_rx_bytes == null ||
prev.net_tx_bytes == null ||
curr.net_tx_bytes == null
) {
rxRates.push(null);
txRates.push(null);
continue;
}
const rxDelta = curr.net_rx_bytes - prev.net_rx_bytes;
const txDelta = curr.net_tx_bytes - prev.net_tx_bytes;
rxRates.push(rxDelta < 0 ? null : rxDelta / dtSec);
txRates.push(txDelta < 0 ? null : txDelta / dtSec);
}
return { rxRates, txRates };
}
function formatBytes(bps: number): string {
if (bps >= 1024 * 1024) return `${(bps / 1024 / 1024).toFixed(1)} MB/s`;
if (bps >= 1024) return `${(bps / 1024).toFixed(1)} KB/s`;
return `${Math.round(bps)} B/s`;
}
export function NetworkCard({
metrics,
hostId,
}: {
metrics: ServerMetrics | null;
hostId: number | null;
}) {
const { t } = useTranslation();
const [activeTab, setActiveTab] = useState<HistoryTab>("live");
const [rows, setRows] = useState<MetricsHistoryRow[] | null>(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (activeTab === "live" || hostId == null) return;
let cancelled = false;
setLoading(true);
setRows(null);
getMetricsHistory(hostId, { range: activeTab })
.then((res) => {
if (!cancelled) {
setRows(res.rows);
setLoading(false);
}
})
.catch(() => {
if (!cancelled) setLoading(false);
});
return () => {
cancelled = true;
};
}, [activeTab, hostId]);
const interfaces = metrics?.network?.interfaces ?? [];
const { rxRates, txRates } = rows
? computeNetRates(rows)
: { rxRates: [], txRates: [] };
const netMax = Math.max(
rxRates.reduce<number>((m, v) => (v != null && v > m ? v : m), 0),
txRates.reduce<number>((m, v) => (v != null && v > m ? v : m), 0),
1024,
);
const timestamps = rows?.map((r) => r.ts) ?? [];
const hasNetData = rxRates.some((v) => v !== null);
const rxSeries: LineChartSeries = {
key: "rx",
label: t("metricsHistory.download"),
color: "var(--chart-2)",
data: rxRates,
};
const txSeries: LineChartSeries = {
key: "tx",
label: t("metricsHistory.upload"),
color: "var(--chart-5)",
data: txRates,
};
return (
<MetricCard
title={t("hostMetrics.networkInterfaces")}
icon={<Network className="size-3.5" />}
scroll
scroll={activeTab === "live"}
action={
hostId != null ? (
<CardTimeTabs value={activeTab} onChange={setActiveTab} />
) : undefined
}
>
{interfaces.length === 0 ? (
<div className="flex flex-col items-center justify-center gap-2 py-6 text-muted-foreground">
<WifiOff className="size-6 opacity-40" />
<span className="text-xs">{t("hostMetrics.noInterfacesFound")}</span>
</div>
) : (
<div className="flex flex-col gap-2">
{interfaces.map((iface, i) => (
<div
key={`${iface.name}-${i}`}
className="flex flex-col gap-1 border border-border bg-muted/30 p-2"
>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
{ifaceIcon(iface.name)}
<span
className={`size-1.5 rounded-full ${iface.state === "UP" ? "bg-accent-brand" : "bg-muted-foreground/50"}`}
/>
<span className="font-mono text-sm font-bold">
{iface.name}
{activeTab === "live" &&
(interfaces.length === 0 ? (
<div className="flex flex-col items-center justify-center gap-2 py-6 text-muted-foreground">
<WifiOff className="size-6 opacity-40" />
<span className="text-xs">
{t("hostMetrics.noInterfacesFound")}
</span>
</div>
) : (
<div className="flex flex-col gap-2">
{interfaces.map((iface, i) => (
<div
key={`${iface.name}-${i}`}
className="flex flex-col gap-1 border border-border bg-muted/30 p-2"
>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
{ifaceIcon(iface.name)}
<span
className={`size-1.5 rounded-full ${iface.state === "UP" ? "bg-accent-brand" : "bg-muted-foreground/50"}`}
/>
<span className="font-mono text-sm font-bold">
{iface.name}
</span>
</div>
<span className="border border-border px-1.5 py-px text-[10px] font-semibold uppercase text-muted-foreground">
{iface.state}
</span>
</div>
<span className="border border-border px-1.5 py-px text-[10px] font-semibold uppercase text-muted-foreground">
{iface.state}
</span>
</div>
<div className="flex justify-between font-mono text-[10px] text-muted-foreground">
<span className="truncate">{iface.ip}</span>
{(iface.rx || iface.tx) && (
<span className="shrink-0">
{iface.rx ?? "—"} / {iface.tx ?? "—"}
</span>
)}
<div className="flex justify-between font-mono text-[10px] text-muted-foreground">
<span className="truncate">{iface.ip}</span>
{(iface.rx || iface.tx) && (
<span className="shrink-0">
&#8595; {iface.rx ?? "—"} / &#8593; {iface.tx ?? "—"}
</span>
)}
</div>
</div>
))}
</div>
))}
{activeTab !== "live" && (
<>
{loading && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("common.loading")}
</div>
))}
</div>
)}
{!loading && rows !== null && !hasNetData && (
<div className="flex h-36 items-center justify-center text-xs text-muted-foreground">
{t("metricsHistory.noData")}
</div>
)}
{!loading && hasNetData && (
<LineChart
series={[rxSeries, txSeries]}
timestamps={timestamps}
domain={[0, netMax]}
yFormatter={formatBytes}
height={160}
/>
)}
</>
)}
</MetricCard>
);
@@ -0,0 +1,56 @@
import { Thermometer } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { ServerMetrics } from "@/main-axios";
import { StatRow } from "@/components/charts";
import { MetricCard } from "./MetricCard";
function formatTemperature(value: number | null | undefined): string {
return typeof value === "number" && Number.isFinite(value)
? `${value.toFixed(1)}°C`
: "N/A";
}
export function TemperatureCard({
metrics,
}: {
metrics: ServerMetrics | null;
}) {
const { t } = useTranslation();
const temperature = metrics?.temperature;
const sensors = temperature?.sensors ?? [];
return (
<MetricCard
title={t("hostMetrics.temperature")}
icon={<Thermometer className="size-3.5" />}
scroll={sensors.length > 4}
scrollMax={220}
>
<div className="flex flex-col gap-3">
<div>
<div className="text-3xl font-semibold tabular-nums">
{formatTemperature(temperature?.highestCelsius)}
</div>
<div className="mt-1 text-xs text-muted-foreground">
{t("hostMetrics.highestTemperature")}
</div>
</div>
{sensors.length === 0 ? (
<span className="text-xs text-muted-foreground">N/A</span>
) : (
<div className="flex flex-col divide-y divide-border">
{sensors.map((sensor) => (
<StatRow
key={`${sensor.label}-${sensor.celsius}`}
label={sensor.label}
value={formatTemperature(sensor.celsius)}
mono
/>
))}
</div>
)}
</div>
</MetricCard>
);
}
+26 -4
View File
@@ -12,6 +12,7 @@ import { LoginStatsCard } from "./LoginStatsCard";
import { PortsCard } from "./PortsCard";
import { ProcessesCard } from "./ProcessesCard";
import { FirewallCard } from "./FirewallCard";
import { TemperatureCard } from "./TemperatureCard";
import { ServiceManagerCard } from "./managers/ServiceManagerCard";
import { ProcessInspectorCard } from "./managers/ProcessInspectorCard";
import { PackageManagerCard } from "./managers/PackageManagerCard";
@@ -26,6 +27,8 @@ import {
SystemdTimersCard,
DiskBreakdownCard,
} from "./managers/SimpleManagerCards";
import { WireGuardManagerCard } from "./managers/WireGuardManagerCard";
import { TailscaleManagerCard } from "./managers/TailscaleManagerCard";
export interface MetricCardHistories {
cpu: number[];
@@ -47,10 +50,14 @@ export interface CardDefinition {
render: (ctx: CardRenderContext) => ReactNode;
}
type SimpleMetricCard = ComponentType<{ metrics: ServerMetrics | null }>;
type SimpleMetricCard = ComponentType<{
metrics: ServerMetrics | null;
hostId: number | null;
}>;
type HistoryMetricCard = ComponentType<{
metrics: ServerMetrics | null;
history: number[];
hostId: number | null;
}>;
function metricCard(
@@ -62,7 +69,7 @@ function metricCard(
id,
labelKey,
kind: "metric",
render: ({ metrics }) => <Comp metrics={metrics} />,
render: ({ metrics, hostId }) => <Comp metrics={metrics} hostId={hostId} />,
};
}
@@ -76,8 +83,8 @@ function historyCard(
id,
labelKey,
kind: "metric",
render: ({ metrics, histories }) => (
<Comp metrics={metrics} history={histories[series]} />
render: ({ metrics, histories, hostId }) => (
<Comp metrics={metrics} history={histories[series]} hostId={hostId} />
),
};
}
@@ -117,6 +124,11 @@ export const CARD_DEFINITIONS: Record<string, CardDefinition> = {
ports: metricCard("ports", "hostMetrics.ports.title", PortsCard),
processes: metricCard("processes", "hostMetrics.processes", ProcessesCard),
firewall: metricCard("firewall", "hostMetrics.firewall.title", FirewallCard),
temperature: metricCard(
"temperature",
"hostMetrics.temperature",
TemperatureCard,
),
service_manager: managerCard(
"service_manager",
"hostMetrics.managers.services",
@@ -177,6 +189,16 @@ export const CARD_DEFINITIONS: Record<string, CardDefinition> = {
"hostMetrics.managers.topMemory",
TopMemoryCard,
),
wireguard_manager: managerCard(
"wireguard_manager",
"hostMetrics.managers.wireguard",
WireGuardManagerCard,
),
tailscale_manager: managerCard(
"tailscale_manager",
"hostMetrics.managers.tailscale",
TailscaleManagerCard,
),
};
/** All card ids implemented and available in the Add tray. */
@@ -0,0 +1,171 @@
import { useState } from "react";
import { Power } from "lucide-react";
import { useTranslation } from "react-i18next";
import { useManagerData, useManagerAction } from "./useManagerData";
import { ManagerCardShell } from "./ManagerCardShell";
import { ManagerSearch } from "./ManagerToolbar";
interface TailscalePeer {
hostname: string;
tailscaleIPs: string[];
online: boolean;
isExitNode: boolean;
}
interface TailscaleData {
installed: boolean;
running: boolean;
tailscaleIPs: string[];
hostname: string | null;
peers: TailscalePeer[];
exitNodeInUse: boolean;
}
export function TailscaleManagerCard({ hostId }: { hostId: number | null }) {
const { t } = useTranslation();
const { data, loading, error, refresh } = useManagerData<TailscaleData>(
hostId,
"tailscale",
);
const { busy, run } = useManagerAction(hostId);
const [query, setQuery] = useState("");
const handleToggle = async () => {
if (!data) return;
const action = data.running ? "down" : "up";
await run(
"tailscale",
{ action },
{
action: "action",
loadingMsg: data.running
? t("hostMetrics.managers.tsDisabling")
: t("hostMetrics.managers.tsEnabling"),
successMsg: data.running
? t("hostMetrics.managers.tsDisabled")
: t("hostMetrics.managers.tsEnabled"),
onDone: refresh,
},
);
};
const filteredPeers = (data?.peers ?? []).filter(
(p) =>
!query ||
p.hostname.toLowerCase().includes(query.toLowerCase()) ||
p.tailscaleIPs.some((ip) => ip.includes(query)),
);
const isNotInstalled = data && !data.installed;
return (
<ManagerCardShell
title={t("hostMetrics.managers.tailscale")}
icon={<Power className="size-3.5" />}
loading={loading}
error={error}
onRefresh={refresh}
empty={!!isNotInstalled}
emptyMessage={t("hostMetrics.managers.tsNotInstalled")}
>
{data && (
<div className="flex flex-col">
{/* Status + toggle row */}
<div className="flex items-center justify-between border-b border-border/50 py-1.5">
<div className="flex min-w-0 items-center gap-2">
<span
className={`size-1.5 shrink-0 rounded-full ${data.running ? "bg-accent-brand" : "bg-muted-foreground/40"}`}
/>
<div className="flex min-w-0 flex-col">
<span className="text-xs font-semibold">
{data.running
? t("hostMetrics.managers.tsRunning")
: t("hostMetrics.managers.tsStopped")}
</span>
{data.hostname && (
<span className="truncate font-mono text-[10px] text-muted-foreground">
{data.hostname}
</span>
)}
{data.tailscaleIPs.map((ip) => (
<span
key={ip}
className="truncate font-mono text-[10px] text-muted-foreground/60"
>
{ip}
</span>
))}
</div>
</div>
<div className="flex shrink-0 items-center">
<button
onClick={handleToggle}
disabled={busy || !data.installed}
title={
data.running
? t("hostMetrics.managers.tsDisable")
: t("hostMetrics.managers.tsEnable")
}
className={`flex size-6 items-center justify-center transition-colors disabled:opacity-40 ${
data.running
? "text-accent-brand hover:bg-muted hover:text-destructive"
: "text-muted-foreground hover:bg-muted hover:text-accent-brand"
}`}
>
<Power className="size-3.5" />
</button>
</div>
</div>
{/* Exit node badge */}
{data.exitNodeInUse && (
<div className="border-b border-border/50 px-0 py-1.5">
<span className="text-[10px] text-blue-500">
{t("hostMetrics.managers.tsExitNodeActive")}
</span>
</div>
)}
{/* Peers */}
{(data.peers?.length ?? 0) > 5 && (
<ManagerSearch
value={query}
onChange={setQuery}
count={filteredPeers.length}
/>
)}
{filteredPeers.map((peer) => (
<div
key={peer.hostname}
className="flex items-center justify-between gap-2 border-b border-border/50 py-1.5 last:border-0"
>
<div className="flex min-w-0 items-center gap-2">
<span
className={`size-1.5 shrink-0 rounded-full ${peer.online ? "bg-accent-brand" : "bg-muted-foreground/40"}`}
/>
<div className="flex min-w-0 flex-col">
<span className="truncate text-xs font-semibold">
{peer.hostname}
</span>
{peer.tailscaleIPs.map((ip) => (
<span
key={ip}
className="truncate font-mono text-[10px] text-muted-foreground"
>
{ip}
</span>
))}
</div>
</div>
{peer.isExitNode && (
<span className="shrink-0 text-[10px] text-blue-500">
{t("hostMetrics.managers.tsExitNode")}
</span>
)}
</div>
))}
</div>
)}
</ManagerCardShell>
);
}
@@ -0,0 +1,209 @@
import { useState } from "react";
import {
ChevronDown,
ChevronRight,
Network,
ArrowUp,
ArrowDown,
} from "lucide-react";
import { useTranslation } from "react-i18next";
import { useManagerData, useManagerAction } from "./useManagerData";
import { ManagerCardShell } from "./ManagerCardShell";
interface WireGuardPeer {
publicKey: string;
endpoint: string | null;
allowedIPs: string[];
latestHandshake: number | null;
rxBytes: number;
txBytes: number;
}
interface WireGuardInterface {
name: string;
publicKey: string | null;
listenPort: number | null;
up: boolean;
peers: WireGuardPeer[];
}
interface WireGuardData {
installed: boolean;
interfaces: WireGuardInterface[];
}
function fmtBytes(n: number): string {
if (n >= 1024 * 1024 * 1024)
return `${(n / 1024 / 1024 / 1024).toFixed(1)}GB`;
if (n >= 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)}MB`;
if (n >= 1024) return `${(n / 1024).toFixed(1)}KB`;
return `${n}B`;
}
function fmtHandshake(ts: number | null): string {
if (!ts) return "";
const diff = Math.floor(Date.now() / 1000) - ts;
if (diff < 60) return `${diff}s ago`;
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
return `${Math.floor(diff / 86400)}d ago`;
}
function truncKey(key: string): string {
return key.length > 12 ? `${key.slice(0, 12)}...` : key;
}
export function WireGuardManagerCard({ hostId }: { hostId: number | null }) {
const { t } = useTranslation();
const { data, loading, error, refresh } = useManagerData<WireGuardData>(
hostId,
"wireguard",
);
const { busy, run } = useManagerAction(hostId);
const [expanded, setExpanded] = useState<Set<string>>(new Set());
const toggleExpand = (name: string) => {
setExpanded((prev) => {
const next = new Set(prev);
if (next.has(name)) next.delete(name);
else next.add(name);
return next;
});
};
const handleAction = async (iface: WireGuardInterface) => {
const action = iface.up ? "down" : "up";
await run(
"wireguard",
{ interface: iface.name, action },
{
action: "action",
loadingMsg:
action === "up"
? t("hostMetrics.managers.wgBringingUp", { name: iface.name })
: t("hostMetrics.managers.wgBringingDown", { name: iface.name }),
successMsg:
action === "up"
? t("hostMetrics.managers.wgInterfaceUpDone", { name: iface.name })
: t("hostMetrics.managers.wgInterfaceDownDone", {
name: iface.name,
}),
onDone: refresh,
},
);
};
const isNotInstalled = data && !data.installed;
const isEmpty = data?.installed && data.interfaces.length === 0;
return (
<ManagerCardShell
title={t("hostMetrics.managers.wireguard")}
icon={<Network className="size-3.5" />}
loading={loading}
error={error}
onRefresh={refresh}
empty={isNotInstalled || isEmpty}
emptyMessage={
isNotInstalled
? t("hostMetrics.managers.wgNotInstalled")
: t("hostMetrics.managers.wgNoInterfaces")
}
>
<div className="flex flex-col">
{data?.interfaces.map((iface) => (
<div
key={iface.name}
className="border-b border-border/50 last:border-0"
>
<div className="flex items-center justify-between gap-2 py-1.5">
<button
className="flex min-w-0 flex-1 items-center gap-2 text-left"
onClick={() => toggleExpand(iface.name)}
>
{expanded.has(iface.name) ? (
<ChevronDown className="size-3 shrink-0 text-muted-foreground" />
) : (
<ChevronRight className="size-3 shrink-0 text-muted-foreground" />
)}
<span
className={`size-1.5 shrink-0 rounded-full ${iface.up ? "bg-accent-brand" : "bg-muted-foreground/40"}`}
/>
<div className="flex min-w-0 flex-col">
<span className="text-xs font-semibold font-mono">
{iface.name}
</span>
<span className="text-[10px] text-muted-foreground">
{iface.up ? "up" : "down"}
{iface.listenPort ? ` · :${iface.listenPort}` : ""}
{iface.peers.length > 0 ? ` · ${iface.peers.length}p` : ""}
</span>
</div>
</button>
<button
onClick={() => handleAction(iface)}
disabled={busy}
title={
iface.up
? t("hostMetrics.managers.wgInterfaceDown")
: t("hostMetrics.managers.wgInterfaceUp")
}
className="flex size-6 shrink-0 items-center justify-center text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40"
>
{iface.up ? (
<ArrowDown className="size-3" />
) : (
<ArrowUp className="size-3" />
)}
</button>
</div>
{expanded.has(iface.name) && (
<div className="mb-1 ml-5 flex flex-col border-l border-border/50">
{iface.peers.length === 0 ? (
<span className="px-3 py-1 text-[10px] text-muted-foreground/50">
No peers
</span>
) : (
iface.peers.map((peer) => (
<div
key={peer.publicKey}
className="flex flex-col gap-0.5 border-b border-border/30 px-3 py-1.5 last:border-0"
>
<div className="flex items-center justify-between gap-2">
<span className="font-mono text-[10px] text-muted-foreground">
{truncKey(peer.publicKey)}
</span>
{peer.endpoint && (
<span className="font-mono text-[10px] text-muted-foreground/60">
{peer.endpoint}
</span>
)}
</div>
{peer.allowedIPs.length > 0 && (
<span className="text-[10px] text-muted-foreground/70">
{peer.allowedIPs.join(", ")}
</span>
)}
<div className="flex items-center gap-3 text-[10px] text-muted-foreground/50">
<span>
{t("hostMetrics.managers.wgLastHandshake")}:{" "}
{peer.latestHandshake
? fmtHandshake(peer.latestHandshake)
: t("hostMetrics.managers.wgHandshakeNever")}
</span>
<span>
{fmtBytes(peer.rxBytes)} / {fmtBytes(peer.txBytes)}
</span>
</div>
</div>
))
)}
</div>
)}
</div>
))}
</div>
</ManagerCardShell>
);
}