The 5-Minute Uptime Check: healthz + a Cron Job
You do not need a paid monitoring service to know when your site is down. A /healthz endpoint plus a cron job is a five-minute setup that covers the basics.
Step 1: a health endpoint
Your service exposes a simple endpoint that returns 200 OK when healthy:
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
if dbCheck() != nil {
http.Error(w, "db down", http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})
The key is that it checks something real — a database ping — not just "the process is alive."
Step 2: a cron job that checks it
*/5 * * * * curl -fsS --max-time 10 https://yourdomain.com/healthz > /dev/null 2>&1 || \
(echo "site down" | mail -s "YOUR SITE IS DOWN" [email protected])
Every five minutes: if the health check fails, send an email. That is the whole monitor.
Step 3: make it actually useful
- Test the real URL (through nginx + TLS), not just localhost — you want to catch a broken proxy, not only a dead process.
- Set a timeout (
--max-time) so a hung check cannot silently pass. - Alert on recovery too if you like — but "it is down" is the one that matters.
What this does not cover
It does not give you a dashboard, latency history, or global checks. For a solo service, that is usually fine — the job of a monitor is to tell you something is wrong while you are away from the keyboard. If you later want history, add UptimeRobot or a similar free tier; the healthz endpoint is the same either way.
Five minutes now saves you discovering an outage by a user's angry email. And if you are deciding whether the VPS hosting that service is worth it, run the numbers below first.
Comments (0)
No comments yet.