|
|
@@ -1,11 +1,20 @@
|
|
|
"use client";
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
+import { useState } from "react";
|
|
|
import { get } from "../../lib/api";
|
|
|
|
|
|
export default function ApiHealth() {
|
|
|
+ const [responseTime, setResponseTime] = useState<number | null>(null);
|
|
|
+
|
|
|
const { data, isLoading, error } = useQuery({
|
|
|
queryKey: ["api", "health"],
|
|
|
- queryFn: () => get("/health"),
|
|
|
+ queryFn: async () => {
|
|
|
+ const startTime = performance.now();
|
|
|
+ const result = await get("/health");
|
|
|
+ const endTime = performance.now();
|
|
|
+ setResponseTime(Math.round(endTime - startTime));
|
|
|
+ return result;
|
|
|
+ },
|
|
|
refetchInterval: 30000 // Check every 30 seconds
|
|
|
});
|
|
|
|
|
|
@@ -35,7 +44,7 @@ export default function ApiHealth() {
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <div className="grid grid-cols-1 gap-2 text-sm">
|
|
|
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-2 text-sm">
|
|
|
<div>
|
|
|
<span className="font-medium text-gray-700 dark:text-gray-300">
|
|
|
Status:
|
|
|
@@ -50,6 +59,16 @@ export default function ApiHealth() {
|
|
|
: "Issues Detected"}
|
|
|
</span>
|
|
|
</div>
|
|
|
+ {responseTime !== null && (
|
|
|
+ <div>
|
|
|
+ <span className="font-medium text-gray-700 dark:text-gray-300">
|
|
|
+ Response Time:
|
|
|
+ </span>
|
|
|
+ <span className="ml-2 text-gray-900 dark:text-gray-100">
|
|
|
+ {responseTime}ms
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
{lastChecked && (
|
|
|
<div>
|
|
|
<span className="font-medium text-gray-700 dark:text-gray-300">
|
|
|
@@ -61,7 +80,7 @@ export default function ApiHealth() {
|
|
|
</div>
|
|
|
)}
|
|
|
{error && (
|
|
|
- <div>
|
|
|
+ <div className="md:col-span-2">
|
|
|
<span className="font-medium text-gray-700 dark:text-gray-300">
|
|
|
Error:
|
|
|
</span>
|