SuperGeekery: A blog probably of interest only to nerds by John F Morton.

A blog prob­a­bly of inter­est only to nerds by John F Mor­ton.

Run your own uptime service: Uptime Kuma with Traefik on Laravel Forge

A robot staring intently at a website. the robots has wide eyes like it has been staring at the screen all night long. (Stable Diffusion)

In this post, I will show you how to install Uptime Kuma, an open-source mon­i­tor­ing ser­vice, on your serv­er. The post assumes you’re using Lar­avel Forge, but you can adapt them for oth­er ser­vices. The basic work­flow will stay the same.

Uptime Kuma can mon­i­tor a vari­ety of ser­vices. I use it to watch this site for down­time. If there is an issue, Uptime Kuma will sends a noti­fi­ca­tion to my phone via the Pushover Mes­sage API.

This post is a fol­low-up to Ana­lyt­ics a dif­fer­ent way. Plau­si­ble Ana­lyt­ics on Lar­avel Forge with Trae­fik and Dock­er.. In that post, I wrapped up with a sec­tion on how to host a sta­t­ic site using Trae­fik. That was just a sim­ple exam­ple to demon­strate the flex­i­bil­i­ty of the Trae­fik sys­tem.

This post is just a con­tin­u­a­tion of that pre­vi­ous post and assumes you fol­lowed along with the orig­i­nal post to the point of hav­ing Trae­fik installed on your machine. If so, you can eas­i­ly add Uptime Kuma to your serv­er.

Uptime status Supergeekery

A screenshot of Uptime Kuma monitoring

Why do this? #

Search the web for web site uptime mon­i­tor­ing,” and many options are returned. I’ve tried sev­er­al of them using both the free and paid tiers. At my com­pa­ny, we’re spend­ing hun­dreds of dol­lars annu­al­ly on uptime mon­i­tor­ing ser­vices.

Using a third-par­­ty mon­i­tor­ing tool has many upsides. Most impor­tant­ly, you can assume the mon­i­tor­ing ser­vice will always be online. A third-par­­ty mon­i­tor­ing ser­vice will like­ly be on a dif­fer­ent infra­struc­ture than you use. Also, hav­ing a third-par­­ty solu­tion means you have one less thing to wor­ry about main­tain­ing. I use Uptime Robot to mon­i­tor my util­i­ty serv­er, which includes my Uptime Kuma instal­la­tion. The belt and sus­penders works.

But the same spir­it that drove me to install and use Plau­si­ble Ana­lyt­ics instead of Google Ana­lyt­ics on my per­son­al projects inspired me to try run­ning a mon­i­tor­ing ser­vice. I like hav­ing con­trol over my data. I also enjoy tin­ker­ing and build­ing things. If you can relate, this project is for you too. 

Installing Uptime Kuma #

I’ll refer to Lar­avel Forge because it’s what I use, but if you use anoth­er ser­vice, like Ploi, Run­Cloud, or Server­Pi­lot, you can get through this. I’ve used Lar­avel Forge for years and have been hap­py with it. I have not had a rea­son to move else­where.

As a reminder, the serv­er we set up pre­vi­ous­ly was a Work­er Serv­er, which only has PHP pre-installed. We chose Work­er Serv­er because it is the sim­plest serv­er option in Lar­avel Forge, a ser­vice focused on PHP-based apps. We also installed Dock­er on the serv­er already.

Set up your DNS #

Using the server’s IP address, cre­ate a DNS record, an A record, point­ing to the domain name you want to use. Doing this now allows the new record to prop­a­gate while we pre­pare the app.

Check out the GitHub repo #

Let’s look at the repo we’ll be using: https://​github​.com/​j​o​h​n​f​m​o​r​t​o​n​/​u​p​t​i​m​e​— k​u​m​a​— w​i​t​h​— t​r​a​e​f​i​k​— f​o​r​— l​a​r​a​v​e​l​— forge. The docker-compose.yml file in my repo is near­ly iden­ti­cal to the ver­sion in the orig­i­nal Uptime Kuma repo. I don’t want port 3001 exposed in my instal­la­tion.

Because we’re going to be rout­ing Uptime Kuma with Trae­fik, we need some addi­tion­al con­fig­u­ra­tion which is in the docker-compose.traefik.yml file. You’ll see that we’re expos­ing the 3001 port to Trae­fik.

You can use my repo or fork it.

Make a new app #

In the Lar­avel Forge dash­board, open the New Site sec­tion. Fill in the Direc­to­ry Name field. I named mine uptime-kuma. Select Sta­t­ic HTML as the Project Type and click the Add Site but­ton. 

Install Uptime Kuma in the App sec­tion by choos­ing a Git repo. 

Enter the repos­i­to­ry name, johnfmorton/uptime-kuma-with-traefik-for-laravel-forge, and choose the main branch. 

Uncheck the Install Com­pos­er Depen­den­cies check­box because we are not installing a PHP app. Click Install Repos­i­to­ry.

The repo’s code is now on the serv­er. We must update our envi­ron­men­tal vari­ables and deploy­ment script before com­plet­ing the Uptime Kuma instal­la­tion.

Set up your envi­ron­men­tal vari­ables #

We need four envi­ron­men­tal vari­ables. Only the first is manda­to­ry.

  • URL_FOR_TRAEFIK — This is the URL you used when set­ting up the DNS. It does not include the pro­to­col, i.e., https. See the docker-compose.traefik.yml file.

The oth­er vari­ables are used only in the deploy­ment script for log­ging pur­pos­es.

  • APP_NAME — I used Uptime Kuma” for mine. 
  • GIT_REPO — The URL of the repo.
  • BASE_URL — Here is used the full URL

Update your Uptime Kuma deploy­ment script #

Click the App nav item. Update your Deploy Script to the fol­low­ing.

cd /home/forge/uptime-kuma

# We assume Docker has already been installed using the "Install Docker and Docker-Compose" recipe.
# The "Make .env variables available to deploy script" must be checked in Laravel Forge

# Confirm Docker is installed and available
if ! command -v docker &> /dev/null; then
    echo "Docker is not installed. Please install Docker and try again."
    exit 1

echo "Deploying: ${APP_NAME} at ${BASE_URL}"

if [[ $FORGE_MANUAL_DEPLOY -eq 1 ]]; then
    echo "This deploy was triggered manually."

git pull origin $FORGE_SITE_BRANCH

if [ -f artisan ]; then
    $FORGE_PHP artisan migrate --force

echo "Docker up with docker-compose.yml combined with reverse-proxy/traefik/docker-compose.traefik.yml"
docker-compose -f docker-compose.yml -f reverse-proxy/traefik/docker-compose.traefik.yml up -d --remove-orphans

echo "Deploy complete."

Deploy your Uptime Kuma app #

Now click the Deploy Now but­ton in the Lar­avel Forge dash­board. After the deploy­ment process com­pletes, your URL may return a Bad Gate­way” error while Trae­fik con­fig­ures the rout­ing. Give it rough­ly 20 sec­onds, and then vis­it the URL. You should see a screen allow­ing you to set up an account and con­fig­ure Uptime Kuma.

Set up noti­fi­ca­tions #

Con­fig­ur­ing Uptime Kuma is easy. I sug­gest cre­at­ing noti­fi­ca­tions using Pushover. Uptime Kuma sup­ports Pushover. There is a one-time fee for the app for your phone and anoth­er for your com­put­er, but then it just works. See the Pushover pric­ing page for details.

You can then use the Pushover API just about any­where. It’s a handy tool for your toolk­it.

You should now have your own mon­i­tor­ing ser­vice set up.