GO திசைGoDisai

Story 12 · Uptime Kuma

The Watchman Who Lives Next Door

“A service is not up because it was up the last time you looked.”

17 min read · by Syed Jafer K

1. The Reminder That Never Went

At GoDisai, a reminder email goes out one hour before every live class. It carries the meeting link. Learners do not think about it, which is the best thing that can be said about any email.

One Thursday it did not go out.

Priya found out at nine minutes past seven in the evening, when Meena, who looks after the learner community, called her. The class had started at seven. Four learners had joined. There were usually more than two hundred.

"They are asking for the link," said Meena. "All of them. At once."

Priya logged in to the server. The mailing service had stopped at two in the afternoon. The disk had filled up, the database had refused to write, and the program had given up. It had been down for five hours.

Those five hours were what troubled her. Disks fill. Programs stop. She could accept that. What she could not accept was that a machine she was responsible for had been broken since lunch, and the first monitoring system to notice was a person with a telephone.

She counted what was running on that one rented server. A bell for notifications. A web server with its certificates. A nightly backup job. An API workbench for the team. The mailing service. Five things, and nothing watching any of them.

That night she sent a message to Karthik, who had helped her with the earlier ones.

"How do you know your things are running?"

"I do not check," he replied. "Something checks for me. It is called Uptime Kuma. Do you have a second machine?"

"Why a second machine?"

"We will get to that. It is the whole story."


2. What Uptime Kuma Is

Uptime Kuma is a monitoring tool that you run yourself. You give it a list of things to check and how often. It checks them, keeps a history, and tells you when something changes.

Louis Lam created it. He has written that he wanted a self-hosted alternative to a popular hosted uptime service. It is free and open source, under the MIT licence.

Karthik described the whole idea with three words: ask, remember, tell.

Step What happens The word for it
Ask Every so often, try to reach a service A check, or heartbeat
Remember Write down whether it answered and how fast The history
Tell When it stops answering, or starts again, send a message A notification

One thing you watch, with its own address and timing, is called a monitor. A server with five services might have eight or ten monitors, because one service can be checked in more than one way.

It can check By doing this
A website or API An HTTP or HTTPS request
A page that must contain certain words The HTTP keyword check
A field in a JSON reply The HTTP JSON query check
A database or any network port Opening a TCP connection
A machine A ping
A domain name A DNS lookup
A job that runs and finishes A push, where the job calls the monitor

There are more types than these, for containers, message queues and databases. Priya needed the ones in this table.

What it is not. Uptime Kuma tells you that something is not answering. It does not tell you why. Graphs of memory, processor and disk are the work of other tools.


3. Where the Watchman Should Live

Priya opened a terminal on her server, ready to install it. Karthik stopped her.

"Not there."

"It has room."

"It had room until Thursday. Suppose the disk fills again. What happens to the mailing service?"

"It stops."

"And to a monitor on the same disk?"

She took her hand off the keyboard.

A watchman who lives inside the house is asleep when the house is. If the server loses power, loses its network or fills its disk, a monitor on that server goes silent with everything else. Silence looks exactly like good news.

Where the monitor runs What it can notice What it misses
The same server as the services One program stopping The server going down, the network going down
A second server at the same provider A server going down The whole provider having a bad day
A machine somewhere else entirely Nearly everything a visitor would notice Private services it cannot reach

They settled on a small, separate server from a different provider. It would do nothing but watch.

"And who watches the watchman?" asked Priya.

"Keep that question," said Karthik. "It comes back in section 14."


4. The First Run

The new server had Docker on it and nothing else. The project's documented command is a single line.

docker run -d --restart=always -p 127.0.0.1:3001:3001 -v uptime-kuma:/app/data --name uptime-kuma louislam/uptime-kuma:2

Karthik made her read it piece by piece.

Part Meaning
-d Run in the background
--restart=always Start again after a crash or a reboot
-p 127.0.0.1:3001:3001 Port 3001, reachable only from this machine
-v uptime-kuma:/app/data Keep all data in a volume that outlives the container
--name uptime-kuma A name to use in later commands
louislam/uptime-kuma:2 The image, on the version 2 line

The 127.0.0.1 in the port matters. Without it, the program listens on every network interface, and on a rented server that means the whole internet can see the setup page. Priya kept it private until the door had a lock.

If you prefer Compose, this does the same job.

services:
  uptime-kuma:
    image: louislam/uptime-kuma:2
    restart: unless-stopped
    volumes:
      - ./data:/app/data
    ports:
      - "127.0.0.1:3001:3001"
docker compose up -d

Keep the data on a local disk. The project says plainly that network file systems such as NFS are not supported. The database relies on file locks, and without them it can be corrupted.

From her laptop, Priya opened a tunnel to the server so that she could reach the private port.

ssh -L 3001:127.0.0.1:3001 priya@watch.example.org

Then she opened http://127.0.0.1:3001 in her browser. It asked her to choose a database. She picked SQLite, the simple single-file option recommended for small setups. Next it asked for an administrator name and password. She used her password manager to make one she could not possibly remember.


5. The First Monitor

An empty dashboard has one obvious button. Priya added a monitor for the mailing service, the one that had hurt her.

Field What she chose Why
Monitor Type HTTP(s) It has a web address
Friendly name Mailing service A name she would understand at 2 a.m.
URL https://mail.example.org The address learners and the team really use
Heartbeat Interval 60 seconds Soon enough, without being noisy
Retries 2 One slow reply should not wake anyone
Heartbeat Retry Interval 30 seconds Check again quickly when something looks wrong

She saved it. A green bar appeared, and a minute later a second one.

Retries deserve a moment. It is the number of failed attempts Uptime Kuma allows before it declares the service down and sends a message. On version 2, a new monitor starts with no retries, so a single dropped request raises an alarm. A small number of retries trades a minute or two of delay for far fewer false alarms.

"An alarm that is often wrong," said Karthik, "is an alarm you will learn to ignore. Then you will ignore the right one too."


6. A Page That Answers Is Not a Page That Works

Priya added the other web addresses and watched them turn green. She was pleased. Karthik asked her an awkward question.

"If the API workbench lost its database tonight, would the front page still load?"

She thought about it. "Probably. The page is static files."

"So your bar stays green while nobody can sign in."

There are three ways to ask a better question.

Look for words on the page. The HTTP(s) - Keyword type fetches the page and then searches for a word you give it. If the word is missing, the service counts as down, even though the server replied.

Look inside a JSON reply. If a service offers a health address that returns something like a status field, the HTTP(s) - Json Query type can check the value of that field.

Check the part underneath. A TCP Port monitor confirms that something accepts connections on a given port. It suits a service that does not speak HTTP.

The question you want answered Monitor type
Does the server reply at all HTTP(s)
Does the reply contain what a real page contains HTTP(s) - Keyword
Does the application report itself healthy HTTP(s) - Json Query
Is the port open TCP Port
Is the machine reachable Ping

Do not open a database to the internet so that a monitor can check it. If the database is private, keep it private, and watch it through a health address in the application or with a push monitor from inside.


7. Telling Somebody

A green dashboard that nobody is looking at is no better than the Thursday afternoon. The next step was notifications.

Uptime Kuma supports many services. Email, Telegram, Slack, Discord and ntfy, the little bell from Chapter 1, are among them.

"Use the bell," said Priya at once. "It is already running."

"Running where?"

On the main server. If that server went down, the watchman would notice, reach for the bell, and find that the bell had gone down with the house.

So she set up two channels.

Channel Where it lives What it is for
ntfy Her own server Everyday alerts, instant on the phone
Email through an outside provider Somewhere else entirely The alert that still arrives when the server is gone

In the notification settings she added ntfy with the server address, a topic and the sign-in token for that topic. Then she added email with the sending details from her outside provider. Each notification has a Test button. She pressed both, and heard her phone twice.

She attached both channels to every monitor. A channel that exists but is not attached to a monitor says nothing, which is an easy mistake to make.

There is one more setting worth knowing. Resend Notification if Down X times consecutively repeats the alert while a service stays down. A single message at 3 a.m. is easy to sleep through.

Break something on purpose. Stop a service, wait, and check that the message arrives on every channel. Then start it and check for the recovery message. An alert you have never received is a theory.

Priya stopped the API workbench. Ninety seconds or so later her phone buzzed. She started it again, and a second message told her it was back.


8. Watching the Backup That Runs at Night

The nightly backup from Chapter 4 had no web address. It woke at two, copied files and went away. There was nothing to ask.

"Turn it round," said Karthik. "Do not ask the job. Make the job report to you."

A Push monitor works the other way. Uptime Kuma gives you a special address, the Push URL, and waits. Your job calls the address when it finishes. If the call does not arrive in time, the monitor goes down.

She created a push monitor named Nightly backup with a heartbeat interval of 90000 seconds, which is 25 hours. A daily job needs a day, plus a little room to run late. Then she added two lines to the end of the backup script.

#!/usr/bin/env bash
set -euo pipefail

rclone sync /srv/data vault:data --backup-dir "vault:old/$(date +%F)"

# Reached only if every command above succeeded
PUSH_URL="$(cat /etc/backup/push-url)"
curl -fsS --max-time 20 "$PUSH_URL" > /dev/null

The important line is set -euo pipefail. It makes the script stop at the first failure. The call to the monitor sits at the end, so it happens only when the backup really worked. A failed backup makes no call, and silence raises the alarm.

This was the part she liked best. Every other monitor reported something that had happened. This one reported something that had not happened.

The Push URL is a secret. Anyone who has it can tell your monitor that all is well. Keep it in a file that only the job can read, not in the script and not in Git. The monitor page has a button to reset the token if it leaks.


9. The Padlock With a Date On It

Karthik had told her once about the morning his certificate expired, back in Chapter 3. Caddy now renewed hers by itself.

"So I do not need to watch it."

"Automatic things fail quietly. That is what makes them dangerous."

On each HTTPS monitor she ticked Certificate Expiry Notification. In the settings, under TLS Certificate Expiry, she could choose how many days before expiry she wanted to be told.

She chose numbers that would only be reached if renewal had already failed. A message then would mean something is wrong with the automation, with days still left to fix it.


10. A Proper Address and HTTPS

The tunnel had been fine for setting up. For daily use, and for the status page, the watchman needed a name.

The watching server got its own Caddy, with three lines.

status.example.org {
    reverse_proxy 127.0.0.1:3001
}

Three things to remember when you do this.

  1. Uptime Kuma uses WebSockets. Caddy handles them with the lines above. Nginx and Apache need extra Upgrade and Connection headers, and without them the page loads but never comes to life.
  2. Use a domain or a subdomain. Serving it under a path such as example.org/uptime is not supported.
  3. Tell it there is a proxy. In the settings, turn Trust Proxy on, and only when the program can be reached through the proxy alone.

Then Priya turned on two-factor authentication in the settings. The dashboard lists every service she runs and holds the tokens for her notification channels. It deserves more than a password.

If you forget the administrator password, it can be reset from the machine itself.

docker exec -it uptime-kuma bash
npm run reset-password

That is also a reminder that anyone who can run commands on the server can take over the monitor. Guard the server.


11. The Status Page

Meena had one request, and it came from the Thursday evening.

"When something breaks, I want to know before two hundred people ask me. And I want something to send them."

A status page is a public page that shows chosen monitors and whether they are up. Priya made one with the services a learner would care about, and gave them plain names.

Monitor name Name on the status page
listmonk HTTPS Class reminder emails
Hoppscotch keyword Not shown, only the team uses it
Nightly backup push Not shown, it is internal
Portal health Course portal

Two details from the documentation are worth knowing before you rely on it.

  • The page is cached for five minutes and refreshes every five minutes. Your dashboard and your notifications are quicker than the page. Do not use the status page as your alarm.
  • The page is public. Anything you put on it, including the names, is visible to anyone. Leave internal services off.

When there is a problem, she can post a short notice on the page. When she plans work, the Maintenance feature lets her schedule a window in advance, so that expected downtime does not set off the alarms.


12. Backups for the Watchman

All of it, the monitors, the history, the notification settings, lives in the data volume. Lose the volume and the watchman forgets whom it was watching.

The older option to export settings as a JSON file was removed in version 2. The supported way is to copy the data directory. Stop the container first, so that the database is not changing while you copy it.

mkdir -p /var/backups/uptime-kuma
docker stop uptime-kuma
docker run --rm \
  -v uptime-kuma:/data:ro \
  -v /var/backups/uptime-kuma:/backup \
  alpine tar czf "/backup/uptime-kuma-$(date +%F).tar.gz" -C /data .
docker start uptime-kuma

The copy holds tokens and passwords for the notification channels. Encrypt it before it leaves the machine, as in Chapter 4.

A restore you have tried is the only kind that counts. Unpack one copy into a spare volume on your laptop, start a container on it, and see your monitors appear. Be ready for it to start checking and sending alerts from there too, so do it with the network off, or stop it as soon as you have looked.


13. Keeping It Healthy

Updating is a matter of replacing the container. The volume stays.

docker pull louislam/uptime-kuma:2
docker stop uptime-kuma
docker rm uptime-kuma
docker run -d --restart=always -p 127.0.0.1:3001:3001 -v uptime-kuma:/app/data --name uptime-kuma louislam/uptime-kuma:2

With Compose it is shorter.

docker compose pull
docker compose up -d --force-recreate

Back up before updating, and read the release notes. A move between major versions needs more care. The jump from version 1 to version 2 migrated the database, could take hours on a slow machine, and must not be interrupted. The :2 tag keeps you on the version 2 line, so a new major version will not arrive by surprise.

Once a month, Priya spends ten minutes on the monitors themselves.

  • Remove monitors for services that no longer exist.
  • Add monitors for services started since last month.
  • Look at response times that have crept upward.
  • Send a test message on every channel.

14. Who Watches the Watchman

Priya had not forgotten her question.

The watching server could die too. Its disk could fill. And a dead watchman sends no message to say so.

No single machine solves this. What you can do is make sure two different things would have to fail together. Priya added a small job on the main server that asked, every five minutes, whether the watchman was still answering.

#!/usr/bin/env bash
# /home/priya/bin/watch-the-watchman.sh
if ! curl -fsS --max-time 20 https://status.example.org > /dev/null; then
  curl -fsS -H "Authorization: Bearer $(cat /home/priya/.ntfy-token)" \
    -d "The monitoring server is not answering" \
    https://ntfy.example.org/alerts
fi
*/5 * * * * /home/priya/bin/watch-the-watchman.sh

Now the two machines watch each other. If the main server dies, the watchman sends email. If the watchman dies, the main server rings the bell. Both dying in the same five minutes is possible, and she decided she could live with that.


15. When Things Go Wrong

What she saw The likely reason What to try
Down alerts that recover at once No retries, or a slow service Add one or two retries
Monitor is green but users complain The check is too shallow Use a keyword or JSON query check
Every monitor goes down together The watching server lost its network Test from that server with curl
No message on a real outage The channel is not attached to the monitor Open the monitor and tick the channel, then test
The dashboard loads but stays blank The proxy is not passing WebSockets Check the proxy settings
Push monitor goes down every day The interval is shorter than the job's real gap Allow the full period plus some slack
Database errors after a move The data is on a network file system Move it to a local disk

16. Small Habits That Keep It Safe

  • Run the monitor somewhere other than the things it watches.
  • Keep at least one alert channel outside your own servers.
  • Never leave the setup page open to the internet.
  • Turn on two-factor authentication.
  • Treat Push URLs and notification tokens as passwords.
  • Put only what outsiders need on the status page.
  • Test your alerts by breaking something on purpose.
  • Delete monitors you have started ignoring, or fix what they are telling you.

17. Epilogue: Nine Minutes to Seven

Some weeks later, on another Thursday, Priya's phone buzzed at twelve minutes past two.

Class reminder emails is down.

She was at lunch. She finished the mouthful, opened her laptop and found the same old enemy, a disk nearly full of logs. She cleared them, restarted the service and set a limit so that the logs could not grow like that again. The recovery message arrived at twenty-six minutes past two.

At nine minutes to seven that evening, she was making tea. The reminders had gone out at six. Meena's name did not appear on her phone.

Later Meena did send a message.

"Anything happen today? It was very quiet."

Priya looked at the long green row, with one short red gap in the early afternoon.

"Something happened," she wrote. "You were not the one who had to tell me."


Quick Reference Cheat-Sheet

I want to... Do this
Start it docker run with the louislam/uptime-kuma:2 image, port 3001, a volume on /app/data
Keep it private while setting up Publish 127.0.0.1:3001:3001 and use an SSH tunnel
Check a website HTTP(s) monitor
Check that the page is really right HTTP(s) - Keyword or HTTP(s) - Json Query
Check a port or a machine TCP Port or Ping
Check a nightly job Push monitor, called at the end of the job
Avoid false alarms Set Retries and a Heartbeat Retry Interval
Be told again while it stays down Resend Notification
Catch a failed certificate renewal Certificate Expiry Notification
Show others the state of things A status page
Plan downtime Maintenance
Back up Stop the container, copy the data volume
Update Pull the image, remove the container, run it again with the same volume
Reset a lost password npm run reset-password inside the container

Key takeaways

  1. Monitoring is asking, remembering and telling. A dashboard without notifications only does the first two.
  2. Put the watchman in a different house. A monitor on the same server fails along with everything it watches.
  3. At least one alert channel must not depend on your own servers.
  4. Check what users need, not only that something replies.
  5. Push monitors catch the work that silently did not happen, such as a backup.
  6. Test every alert before you need it.
  7. The data volume is the backup, and it contains secrets.

A monitor will not keep your services running. It only makes sure that when one stops, you are the first to know.