import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import ReadNowButton from "../components/ReadNowButton"; import { api, type CurrentUser, type HetznerProject, type HetznerTrafficForecast } from "../api/client"; import EmptyState from "../components/EmptyState"; import TimeAgo from "../components/TimeAgo"; import { BlockSkeleton } from "../components/Skeleton"; import { ErrorNotice } from "../components/Notice"; import { formatBytes } from "./settings/StorageSettings"; import { readableError } from "../utils/errors"; import PageIntro from "../components/PageIntro"; function Badge({ p }: { p: HetznerProject }) { if (!p.enabled) return Off; if (!p.state) return Not read yet; if (!p.fresh) return Can’t be read; if (p.problems.some((x) => x.severity === "critical")) return Needs a look; if (p.problems.length > 0) return Needs a look; return In order; } export function StatusBadge({ status }: { status: string }) { if (status === "running") return Running; if (status === "off") return Off; return {status}; } const DAY_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; const dayText = (iso: string) => { const d = new Date(iso); return `${d.getUTCDate()} ${DAY_NAMES[d.getUTCMonth()]}`; }; /** What the month's traffic is forecast to come to, and when the quota goes if it is before the month ends. */ export function ForecastText({ forecast, included }: { forecast: HetznerTrafficForecast | null | undefined; included: number | null }) { if (!forecast || included === null || included <= 0) return null; return (
{forecast.exhaustedAt ? <>at this rate the quota is passed on {dayText(forecast.exhaustedAt)} : <>on course for {formatBytes(forecast.projectedMonth)} by the month’s end} · {formatBytes(forecast.perDay)} a day ({forecast.basis === "recent" ? "this week" : "the month"})
); } /** This month's outgoing traffic against what the server includes, as a bar that turns yellow at 80% and red at 100%. */ export function TrafficBar({ used, included }: { used: number | null; included: number | null }) { if (used === null || included === null || included <= 0) return {used === null ? "—" : formatBytes(used)}; const share = used / included; return (
= 1 ? "bg-red" : share >= 0.8 ? "bg-yellow" : "bg-green"}`} style={{ width: `${Math.min(100, share * 100)}%` }} />
{formatBytes(used)} of {formatBytes(included)} ({Math.floor(share * 100)}%)
); } const money = (n: number, currency: string) => { try { return new Intl.NumberFormat(undefined, { style: "currency", currency }).format(n); } catch { return `${n.toFixed(2)} ${currency}`; } }; function ServerRow({ s }: { s: NonNullable["servers"][number] }) { return ( {s.linked ? {s.name} : {s.name}} {!s.linked &&
no agent here — not in the app’s servers
} {s.os &&
{s.os}
} {s.rescueEnabled && rescue on} {s.locked && locked} {s.status !== "running" && (
since
)} {s.type ?? "—"}
{[s.cores !== null ? `${s.cores} cores` : null, s.memoryGb !== null ? `${s.memoryGb} GB RAM` : null, s.diskGb !== null ? `${s.diskGb} GB disk` : null].filter(Boolean).join(" · ")}
{[s.city, s.location].filter(Boolean).join(" · ") || "—"} {s.ipv4 ?? "—"} {s.privateIps.length > 0 &&
{s.privateIps.join(", ")}
} {s.backupWindow ? `on (${s.backupWindow})` : "off"} {s.monthlyPrice === null ? "—" : s.monthlyPrice.toFixed(2)} ); } function Card({ p, canRead, onRead }: { p: HetznerProject; canRead: boolean; onRead: () => void }) { const s = p.state; const cost = s?.cost ?? null; const gb = (s?.volumes ?? []).reduce((sum, v) => sum + v.size, 0); const snapshots = (s?.images ?? []).filter((i) => i.type === "snapshot").sort((a, b) => (b.created ?? "").localeCompare(a.created ?? "")); const backups = (s?.images ?? []).filter((i) => i.type === "backup"); return (

{p.name}

{p.status ? <>read : "not read yet"} {canRead && p.enabled && }
{p.status && !p.status.ok &&
The last attempt to read it failed: {p.status.error ?? "no answer"}.
} {p.problems.length > 0 && (
    {p.problems.map((x) => (
  • {x.message}
  • ))}
)} {s && ( <>
Servers
{s.servers.length}
{s.servers.filter((x) => x.status === "running").length} running
Estimated per month
{cost ? money(cost.total, cost.currency) : "—"}
{cost ? "at list prices, with VAT" : "the price list could not be read"}
Volumes
{s.volumes === null ? "—" : s.volumes.length}
{s.volumes === null ? "could not be read" : `${gb} GB${s.volumes.some((v) => v.serverId === null) ? `, ${s.volumes.filter((v) => v.serverId === null).length} not attached` : ""}`}
Snapshots and backups
{s.images === null ? "—" : `${snapshots.length} + ${backups.length}`}
{s.images === null ? "could not be read" : "snapshots + backups"}
{cost && (
Servers {money(cost.servers, cost.currency)} · backups {money(cost.backups, cost.currency)} · volumes {money(cost.volumes, cost.currency)} · snapshots {money(cost.snapshots, cost.currency)} · primary IPs {money(cost.ips, cost.currency)} · load balancers {money(cost.loadBalancers ?? 0, cost.currency)} · floating IPs {money(cost.floatingIps ?? 0, cost.currency)} {cost.unassignedIps > 0 ? ` (${cost.unassignedIps} not attached to a server)` : ""}. An estimate from Hetzner’s price list: it leaves out traffic over the quota{cost.unpriced > 0 ? `, and ${cost.unpriced} server(s) whose price was not given` : ""}.
)}
{s.servers.map((x) => ( ))} {s.servers.length === 0 && ( )}
Server Status Type Location Address Traffic this month Backups Price/mo
The project has no servers.
{s.loadBalancers && s.loadBalancers.length > 0 && ( <>

Load balancers

{s.loadBalancers.map((l) => { const bad = l.targets.filter((t) => t.health === "unhealthy"); return ( ); })}
Name Type Address Targets Traffic this month Price/mo
{l.name}
{l.services} service{l.services === 1 ? "" : "s"} {l.algorithm ? ` · ${l.algorithm.replace("_", " ")}` : ""}
{[l.type, l.location].filter(Boolean).join(" · ") || "—"} {l.ipv4 ?? "—"} {l.targets.length === 0 ? ( none ) : bad.length === 0 ? ( {l.targets.every((t) => t.health === "healthy") ? `${l.targets.length} healthy` : `${l.targets.length} · not judged yet`} ) : ( {bad.length} of {l.targets.length} unhealthy )}
{l.targets.map((t) => `${t.serverName ?? t.label ?? "target"}${t.health === "unhealthy" ? " ✗" : ""}`).join(", ")}
{l.monthlyPrice === null ? "—" : l.monthlyPrice.toFixed(2)}
)} {s.floatingIps && s.floatingIps.length > 0 && ( <>

Floating IPs

    {s.floatingIps.map((f) => (
  • {f.ip} {f.name ? ` (${f.name})` : ""} — {f.serverId === null ? points at no server (still billed) : f.serverName ? `points at ${f.serverName}` : `points at a server (#${f.serverId})`} {f.location ? `, ${f.location}` : ""}
  • ))}
)} {s.certificates && s.certificates.length > 0 && ( <>

Certificates

    {s.certificates.map((c) => { const left = c.notValidAfter === null ? null : (Date.parse(c.notValidAfter) - Date.now()) / 86_400_000; return (
  • {c.name} ({c.type} {c.domains.length > 0 ? `, ${c.domains.slice(0, 3).join(", ")}${c.domains.length > 3 ? ", …" : ""}` : ""}) —{" "} {c.notValidAfter === null ? ( {c.issuance === "failed" ? "could not be issued" : "being issued"} ) : left !== null && left <= 0 ? ( ended ) : ( ends in {Math.ceil(left ?? 0)} days )} {c.usedBy === 0 && · used by nothing} {(c.issuance === "failed" || c.renewal === "failed") && · {c.issuance === "failed" ? "issuing" : "renewing"} failed{c.error ? `: ${c.error}` : ""}}
  • ); })}
)} {s.volumes && s.volumes.length > 0 && ( <>

Volumes

    {s.volumes.map((v) => (
  • {v.name} — {v.size} GB, {v.location ?? "?"}, {v.serverName ? `on ${v.serverName}` : v.serverId === null ? not attached to a server (still billed) : `on a server (#${v.serverId})`}
  • ))}
)} {snapshots.length > 0 && ( <>

Snapshots

    {snapshots.map((i) => (
  • {i.description ?? `#${i.id}`} — {i.sizeGb === null ? "being made" : `${i.sizeGb.toFixed(1)} GB`}, {i.serverName ? `of ${i.serverName}` : "of a server that is gone"} {i.created && ( <> , taken )}
  • ))}
Snapshots are billed per GB and month until they are deleted.
)} )}
); } /** Hetzner Cloud: each project's servers, what is close to its traffic quota, which have backups, and roughly what it all costs. */ export default function Hetzner({ user }: { user: CurrentUser }) { const canRead = user.role === "admin" || user.role === "operator"; const [tick, setTick] = useState(0); const [data, setData] = useState(null); const [error, setError] = useState(null); useEffect(() => { const load = () => api.hetzner .list() .then((r) => { setData(r.projects); setError(null); }) .catch((err) => setError(readableError(err))); void load(); const t = setInterval(load, 60_000); return () => clearInterval(t); }, [tick]); return ( <>

Hetzner Cloud

One project per integration, read every few minutes (see Integrations) — nothing is started, stopped or changed. A server that was running and is now off, traffic close to the month’s quota,{" "} rescue mode left on, backups that are late, a traffic quota the month is on course to pass, unhealthy load balancer targets, certificates about to end and floating IPs that point at nothing are alerts — see Alerts. {!data && !error && } {data && data.length === 0 && (
)} {data?.map((p) => setTick((n) => n + 1)} />)} ); }