Show latency if status 200
This commit is contained in:
parent
5eb4778f53
commit
8eca0011db
@ -104,6 +104,13 @@ export default function Item({ service }) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="absolute top-0 right-0 w-1/2 flex flex-row justify-end gap-2 mr-2">
|
<div className="absolute top-0 right-0 w-1/2 flex flex-row justify-end gap-2 mr-2">
|
||||||
|
{service.ping && (
|
||||||
|
<div className="flex-shrink-0 flex items-center justify-center cursor-pointer">
|
||||||
|
<Ping service={service} />
|
||||||
|
<span className="sr-only">Ping status</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{service.container && (
|
{service.container && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@ -114,13 +121,6 @@ export default function Item({ service }) {
|
|||||||
<span className="sr-only">View container stats</span>
|
<span className="sr-only">View container stats</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{service.ping && (
|
|
||||||
<div className="flex-shrink-0 flex items-center justify-center cursor-pointer">
|
|
||||||
<Ping service={service} />
|
|
||||||
<span className="sr-only">Ping status</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import useSWR from "swr";
|
|||||||
export default function Ping({ service }) {
|
export default function Ping({ service }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ping: service.ping}).toString()}`, {
|
const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ping: service.ping}).toString()}`, {
|
||||||
refreshInterval: 5000
|
refreshInterval: 30000
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -36,7 +36,7 @@ export default function Ping({ service }) {
|
|||||||
if (data && data.status === 200) {
|
if (data && data.status === 200) {
|
||||||
return (
|
return (
|
||||||
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={statusText}>
|
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={statusText}>
|
||||||
<div className="text-[8px] font-bold text-emerald-500/80">{data.status}</div>
|
<div className="text-[8px] font-bold text-emerald-500/80">{t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", unitDisplay: "narrow", maximumFractionDigits: 0 })}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { performance } from "perf_hooks";
|
||||||
|
|
||||||
import createLogger from "utils/logger";
|
import createLogger from "utils/logger";
|
||||||
import { httpProxy } from "utils/proxy/http";
|
import { httpProxy } from "utils/proxy/http";
|
||||||
|
|
||||||
@ -13,11 +15,14 @@ export default async function handler(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startTime = performance.now();
|
||||||
const [status] = await httpProxy(pingURL, {
|
const [status] = await httpProxy(pingURL, {
|
||||||
method: "HEAD"
|
method: "HEAD"
|
||||||
});
|
});
|
||||||
|
const endTime = performance.now();
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
status,
|
status,
|
||||||
|
latency: endTime - startTime
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user