Why Roll Your Own Monitoring?
Managed monitoring like Datadog is excellent — and expensive. For a self-hosted video platform like TopVideoHub , a 200-line Go binary can cover 90% of what you need: uptime checks, latency histograms, error rate alerts, and a Grafana dashboard wired to Prometheus.
Health Check Endpoints
package main
import ( "database/sql" "encoding/json" "net/http" "time" )
type HealthStatus struct { Status string `json:"status"` Checks map [ string ] string `json:"checks"` Uptime string `json:"uptime"` Ts time . Time `json:"ts"` }
var startTime = time . Now ()
func healthHandler ( db * sql . DB ) http . HandlerFunc { return func ( w http . ResponseWriter , r * http . Request ) { checks := map [ string ] string {} overall := "ok"
if err := db . Ping (); err != nil { checks [ "database" ] = "error: " + err . Error () overall = "degraded" } else { checks [ "database" ] = "ok" }
status := HealthStatus { Status : overall , Checks : checks , Uptime : time . Since ( startTime ) .…