Menu

1 / 2

Monitoring and Alerting for Video Platform Infrastructure with Go

DEV Community·ahmet gedik·6 months ago
#ZhKWo5k7
#go#monitoring#devops#infrastructure#time
Reading 0:00
15s threshold

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 ) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.