Building your own uptime monitoring: what it takes
Not running somebody's tool but writing your own is a different decision from self-hosting, and a more tempting one. A first version is easy: fetch a URL on a timer, compare the status code, send a mail when it is wrong. It works the first time you try it, which is why the long list of what it leaves out only shows up later, during an incident.
What the first version does not do
Judging
- What counts as a failure. A timeout, a refused connection, a name that does not resolve, a certificate that does not verify and a 500 are different failures with different causes. A good result says which.
- How long to wait, and for which part: the name lookup, the connection, the TLS handshake and the first byte each take time, and a slow site and a dead one look alike if you only keep the total.
- Redirects, compression, response size. A check should follow a few redirects and stop, and read a bounded amount of the answer.
- The answer itself. A server that answers 200 with an error page, an empty list or yesterday's data is up by every status-code measure.
Deciding when to alert
- One failure is not an outage. You need a threshold, such as 3 of the last 5 checks, and a separate one for recovery so that a site that comes back for one check does not send an all-clear.
- A check that could not run is not a failed site. Your own network, resolver or process can fail. A result of "unknown" that neither raises nor clears an alert keeps your monitor from reporting its own trouble as your site's.
- Flapping. Something that drops in and out has to be handled by design, or it sends a message every minute.
- Each location on its own, if you check from more than one.
Running on time
- Scheduling. A check that takes longer than its interval, many checks starting at the same second, a restart in the middle of a run, and drift over days.
- Concurrency and limits. Slow targets must not hold up the fast ones.
- Surviving restarts without losing the schedule or the state of every alert.
Delivering alerts
- A path that works when everything else does not, retried when it fails, with repeats suppressed and a record of what was sent and when.
- Several channels with different formats and credentials, each of which can silently expire.
Keeping results
- Storage that grows. Every check, at every interval, forever, until you decide what to keep, for how long and at which resolution.
- Questions you will want to ask, such as the response time last Tuesday or the length of an outage, which need the data in a shape that answers them.
Checking from more than one place
- Running probes in several networks, getting their results back to one place when the network between them is the thing that is failing, and telling a probe's problem from your site's.
Safety
- Which addresses may be checked. If anyone but you can choose a target, a monitor will happily request your internal addresses. The Blackbox Exporter README says it makes requests to any target it is given, and it is meant to be kept away from people who should not be choosing targets.
- Secrets. Headers and credentials for monitored endpoints have to be stored and protected.
Operating it
- Someone has to run it, all the time. It has to be up when your site is down, which is exactly when everything around it is under stress. That means hosting, patching, dependency updates, backups, capacity and a person who is reachable when it breaks.
- Every probe is a server. Checking from more than one place means keeping each of those places running, patched and connected.
- Upgrades and changes have to be tested like any production system, and the monitor is the one system nobody is watching while you do it.
Watching the watcher
- Everything on this list can fail without a sound. Your monitor needs an outside check of its own.
Should we build or buy?
- You need a kind of check no tool offers, or one tied closely to your own systems.
- The point is to learn, or the monitoring is part of what you sell.
- You can give it the care a product needs: tests of the failure paths, an owner and a pager.
A middle path
Start from an existing tool, such as Uptime Kuma, Gatus or the Blackbox Exporter, and build only what is missing: a custom check that reports its result to it, a configuration generated from your own inventory. Then put an independent check, from a service, on the whole thing.
Where Pingsured fits
Pingsured is the part you would otherwise write, and above all the part you would otherwise operate: it is managed, so there is no monitor of your own to host, patch, back up and keep reachable. It covers the schedule, the judging, the thresholds per location, the history, and an alert path that does not depend on your own infrastructure. It sends GET or HEAD requests and ICMP pings to public addresses, and it runs none of your code, so it cannot check what only your own program can.
Questions to ask yourself
- Who will own it in a year, and what happens to it when they leave?
- What does it do when the network between probe and database is the thing that is broken?
- How will I know that it stopped?
- Is the time better spent on what we sell?