Monitoring Your Go API with Vigilmon: Health Endpoints, Alerting & Status Pages
Go is the language of choice for high-performance APIs and microservices. When your Go service goes down, you need to know immediately — before users report it. Vigilmon gives you external multi-region monitoring with zero configuration overhead.
Why External Monitoring for Go Services?
Go services are typically:
- Long-running processes serving HTTP traffic
- Running in containers on Kubernetes or Docker Swarm
- Deployed across multiple environments
Internal metrics (Prometheus, pprof) tell you about runtime performance. External monitoring tells you whether users can actually reach your service.
Adding a Health Check to Your Go Service
Standard Library (net/http)
package main
import (
"encoding/json"
"net/http"
"time"
)
type HealthResponse struct {
Status string `json:"status"`
Timestamp int64 `json:"timestamp"`
}
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(HealthResponse{
Status: "ok",
Timestamp: time.Now().Unix(),
})
}
func main() {
http.HandleFunc("/health", healthHandler)
http.HandleFunc("/api/v1/...", yourAPIHandler)
http.ListenAndServe(":8080", nil)
}
With Gin Framework
package main
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"timestamp": time.Now().Unix(),
})
})
r.Run(":8080")
}
With Echo Framework
package main
import (
"net/http"
"time"
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
e.GET("/health", func(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]interface{}{
"status": "ok",
"timestamp": time.Now().Unix(),
})
})
e.Start(":8080")
}
Adding a Database Check
For a deeper health check that verifies your database connection:
func healthHandler(db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status := "ok"
httpStatus := http.StatusOK
// Quick DB ping with timeout
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
defer cancel()
if err := db.PingContext(ctx); err != nil {
status = "degraded"
httpStatus = http.StatusServiceUnavailable
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(httpStatus)
json.NewEncoder(w).Encode(map[string]string{
"status": status,
})
}
}
Setting Up Vigilmon
- Sign up at vigilmon.online
- Click Add Monitor
- Enter your health endpoint URL:
https://your-go-api.com/health - Set check interval: 1 minute for production APIs
- Add alert destinations: email and/or webhook
- Save
Vigilmon starts checking from multiple geographic regions. If your Go service goes down in 2+ regions simultaneously, you get alerted.
Multi-Service Monitoring
For microservice architectures, monitor each service independently:
| Service | Monitor URL |
|---|---|
| API Gateway | https://api.yourdomain.com/health |
| User Service | https://users.internal.com/health |
| Payment Service | https://payments.yourdomain.com/health |
| Worker (HTTP liveness) | https://worker.yourdomain.com/alive |
Kubernetes Liveness vs External Monitoring
Kubernetes liveness and readiness probes check from inside the cluster. Vigilmon checks from outside the internet. Both are needed:
- K8s probes: Restart unhealthy pods automatically
- Vigilmon: Tell you when users cannot reach your service (ingress issues, DNS, load balancer, etc.)
# k8s liveness probe — checks from inside the cluster
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
Then add the same /health endpoint in Vigilmon monitoring the public URL.
Webhook Integration Example
Vigilmon can POST to any webhook when your service goes down. Example handler to receive Vigilmon alerts:
func vigilmonWebhookHandler(w http.ResponseWriter, r *http.Request) {
var payload map[string]interface{}
json.NewDecoder(r.Body).Decode(&payload)
// Send to Slack, PagerDuty, etc.
log.Printf("Vigilmon alert: %+v", payload)
w.WriteHeader(http.StatusOK)
}
Conclusion
Adding a /health endpoint to your Go service takes 5 minutes. Adding it to Vigilmon takes 2 more. Together they give you external multi-region uptime monitoring with smart false-alert prevention.
Start free at vigilmon.online — 5 monitors, no credit card, live in 2 minutes.