diff options
| author | Bobby <[email protected]> | 2025-04-06 12:03:07 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-04-06 12:03:07 +0530 |
| commit | 8d034c4ad93881ef95aae9760baf6415c28de839 (patch) | |
| tree | 348746bb78356cc72fa871e623c6ea714b5b2bd5 /controllers | |
| parent | c947eb5f6c9bdcd624347f02a1d0b0bc65d96622 (diff) | |
| download | metachan-8d034c4ad93881ef95aae9760baf6415c28de839.tar.xz metachan-8d034c4ad93881ef95aae9760baf6415c28de839.zip | |
added health route for server stats
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/health.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/controllers/health.go b/controllers/health.go new file mode 100644 index 0000000..3f12bce --- /dev/null +++ b/controllers/health.go @@ -0,0 +1,36 @@ +package controllers + +import ( + "metachan/database" + "metachan/tasks" + "metachan/types" + "metachan/utils/stats" + + "github.com/gofiber/fiber/v2" +) + +func HealthStatus(c *fiber.Ctx) error { + // Check if the database is connected + databaseStatus := database.DatabaseConnectionStatus() + + // Get the memory stats + memoryStats := stats.GetMemoryStats() + + // Get the task statuses + taskStatuses := tasks.GlobalTaskManager.GetAllTaskStatuses() + + statusString := map[bool]string{ + true: "healthy", + false: "unhealthy", + }[databaseStatus] + // Create the health status response + healthStatus := types.HealthStatus{ + Status: statusString, + Timestamp: stats.GetCurrentTimestamp(), + Uptime: stats.GetUptime(), + Memory: memoryStats, + Database: types.DatabaseStatus{Connected: databaseStatus, LastChecked: stats.GetCurrentTimestamp()}, + Tasks: taskStatuses, + } + return c.JSON(healthStatus) +} |
