import useSWR from "swr"; import { calculateCPUPercent, formatBytes } from "utils/stats-helpers"; import Stat from "./stat"; export default function Stats({ service }) { // fast const { data: statusData, error: statusError } = useSWR( `/api/docker/status/${service.container}/${service.server || ""}`, { refreshInterval: 1500, } ); // takes a full second to collect stats const { data: statsData, error: statsError } = useSWR( `/api/docker/stats/${service.container}/${service.server || ""}`, { refreshInterval: 1500, } ); // handle errors first if (statsError || statusError) { return (
); } // handle the case where we get a docker error if (statusData.status !== "running") { return (
); } // handle the case where the container is offline if (statusData.status !== "running") { return (
); } // handle the case where we don't have anything yet if (!statsData || !statusData) { return (
); } // we have stats and the container is running return (
); }