summaryrefslogtreecommitdiff
path: root/src/components/server/Uptime.astro
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/components/server/Uptime.astro43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/components/server/Uptime.astro b/src/components/server/Uptime.astro
index ff65f3e..c034ec3 100644
--- a/src/components/server/Uptime.astro
+++ b/src/components/server/Uptime.astro
@@ -10,11 +10,14 @@ interface Props {
}
const { name } = Astro.props;
+let show = true;
+
// Ensure ENV variables are set
if (!KUMA_URL || !KUMA_API_KEY) {
- Astro.response.status = 500;
- Astro.response.statusText = "Internal Server Error";
- return;
+ console.warn(
+ "Uptime Kuma URL or API Key is not set. Skipping Uptime component.",
+ );
+ show = false;
}
// Fetch the metrics from Uptime Kuma
@@ -25,9 +28,10 @@ const response = await fetch(`${KUMA_URL}/metrics`, {
});
if (!response.ok) {
- Astro.response.status = response.status;
- Astro.response.statusText = response.statusText;
- return;
+ console.warn(
+ `Failed to fetch metrics from Uptime Kuma: ${response.status} ${response.statusText}`,
+ );
+ show = false;
}
// Parse the metrics to find the status of the monitor with the given name
@@ -50,9 +54,8 @@ const status = metrics
.map((m) => m.status)[0];
if (status == null) {
- Astro.response.status = 404;
- Astro.response.statusText = "Not Found";
- return;
+ console.warn(`Monitor with name "${name}" not found in Uptime Kuma metrics.`);
+ show = false;
}
// Map the status to a color
@@ -72,11 +75,17 @@ Astro.response.headers.set(
);
---
-<span class="absolute -top-1.5 -right-1 w-2.5 h-2.5">
- <span
- class="absolute inset-0 rounded-full bg-gray-500 opacity-75 motion-safe:animate-ping"
- style={style}></span>
- <span
- class="relative block w-2.5 h-2.5 rounded-full bg-gray-500 shadow shadow-green-400/50"
- style={style}></span>
-</span>
+{
+ show && (
+ <span class="absolute -top-1.5 -right-1 w-2.5 h-2.5">
+ <span
+ class="absolute inset-0 rounded-full bg-gray-500 opacity-75 motion-safe:animate-ping"
+ style={style}
+ />
+ <span
+ class="relative block w-2.5 h-2.5 rounded-full bg-gray-500 shadow shadow-green-400/50"
+ style={style}
+ />
+ </span>
+ )
+}