Discord Bot Health Check Utility
cgen-81844a0938b04c7ba11cfc8e5ff3d1c5
This commit is contained in:
parent
81dca160b4
commit
cd4953be8d
1 changed files with 65 additions and 0 deletions
65
client/lib/discord-bot-status.ts
Normal file
65
client/lib/discord-bot-status.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
export interface BotHealthStatus {
|
||||
status: "online" | "offline";
|
||||
guilds: number;
|
||||
commands: number;
|
||||
uptime: number;
|
||||
timestamp: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
const BOT_HEALTH_URL = "http://144.217.139.239:25611/health";
|
||||
|
||||
export async function checkBotHealth(): Promise<BotHealthStatus> {
|
||||
try {
|
||||
const response = await fetch(BOT_HEALTH_URL, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
status: "offline",
|
||||
guilds: 0,
|
||||
commands: 0,
|
||||
uptime: 0,
|
||||
timestamp: new Date().toISOString(),
|
||||
error: `HTTP ${response.status}: Failed to reach bot`,
|
||||
};
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return {
|
||||
status: data.status || "online",
|
||||
guilds: data.guilds || 0,
|
||||
commands: data.commands || 0,
|
||||
uptime: data.uptime || 0,
|
||||
timestamp: data.timestamp || new Date().toISOString(),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("[Discord Bot Status] Error checking health:", error);
|
||||
return {
|
||||
status: "offline",
|
||||
guilds: 0,
|
||||
commands: 0,
|
||||
uptime: 0,
|
||||
timestamp: new Date().toISOString(),
|
||||
error:
|
||||
error instanceof Error ? error.message : "Failed to reach bot health endpoint",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function formatUptime(seconds: number): string {
|
||||
const days = Math.floor(seconds / 86400);
|
||||
const hours = Math.floor((seconds % 86400) / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
const parts = [];
|
||||
if (days > 0) parts.push(`${days}d`);
|
||||
if (hours > 0) parts.push(`${hours}h`);
|
||||
if (minutes > 0) parts.push(`${minutes}m`);
|
||||
|
||||
return parts.length > 0 ? parts.join(" ") : "< 1m";
|
||||
}
|
||||
Loading…
Reference in a new issue