import { useEffect, useMemo } from "preact/hooks"; import { useSignal } from "@preact/signals"; const latencySamples = [18, 21, 24, 19, 22, 27, 20, 23, 25]; function getLatency() { const jitter = Math.floor(Math.random() * 4) - 2; // -2..1 const base = latencySamples[Math.floor(Math.random() * latencySamples.length)]; return Math.max(12, base + jitter); } export default function ServerStatus() { const latency = useSignal(getLatency()); const status = useSignal<"online" | "warning">("online"); useEffect(() => { const interval = setInterval(() => { const value = getLatency(); latency.value = value; status.value = value > 28 ? "warning" : "online"; }, 1400); return () => clearInterval(interval); }, []); const statusLabel = useMemo( () => (status.value === "online" ? "Operacional" : "Oscilação"), [status.value], ); return (
{latency.value}ms
latência média