2023-03-05 14:57:20 -08:00
|
|
|
import useSWR from "swr";
|
|
|
|
import { FaRegClock } from "react-icons/fa";
|
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
2023-06-05 23:18:18 +01:00
|
|
|
import Resource from "../widget/resource";
|
2023-06-03 01:10:15 +01:00
|
|
|
import Error from "../widget/error";
|
|
|
|
|
2023-07-27 01:35:48 +02:00
|
|
|
export default function Uptime({ refresh = 1500 }) {
|
2023-03-05 14:57:20 -08:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2023-10-18 11:44:26 -07:00
|
|
|
const { data, error } = useSWR(`/api/widgets/resources?type=uptime`, {
|
2023-07-27 01:35:48 +02:00
|
|
|
refreshInterval: refresh,
|
2023-03-05 14:57:20 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (error || data?.error) {
|
2023-10-17 23:26:55 -07:00
|
|
|
return <Error />;
|
2023-03-05 14:57:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!data) {
|
2023-06-05 23:18:18 +01:00
|
|
|
return <Resource icon={FaRegClock} value="-" label={t("resources.uptime")} percentage="0" />;
|
2023-03-05 14:57:20 -08:00
|
|
|
}
|
|
|
|
|
2023-06-05 23:18:18 +01:00
|
|
|
const percent = Math.round((new Date().getSeconds() / 60) * 100).toString();
|
2023-03-31 10:37:31 -07:00
|
|
|
|
2023-12-15 14:08:37 -08:00
|
|
|
return (
|
|
|
|
<Resource
|
|
|
|
icon={FaRegClock}
|
|
|
|
value={t("common.uptime", { value: data.uptime })}
|
|
|
|
label={t("resources.uptime")}
|
|
|
|
percentage={percent}
|
|
|
|
/>
|
|
|
|
);
|
2023-03-05 14:57:20 -08:00
|
|
|
}
|