How to Install Healthchecks on NixOS Latest?

Healthchecks is a monitoring tool based on Python that checks if your software services are running properly, provides alerts if services fail, and records the availability metrics of your services. In this tutorial, we will guide you through how to install Healthchecks on NixOS Latest.

Prerequisites

Before installing Healthchecks on NixOS Latest, make sure you have the following:

Step 1: Install Database

Healthchecks requires a database for storing monitoring data. In this tutorial, we will use PostgreSQL.

  1. Open your terminal and run the following command to install PostgreSQL:
sudo nix-env -iA nixos.postgresql
  1. After installation, start PostgreSQL and enable it at boot:
sudo systemctl start postgresql
sudo systemctl enable postgresql

Step 2: Install Healthchecks

  1. Open your terminal and create a new directory for Healthchecks:
mkdir ~/healthchecks
cd ~/healthchecks
  1. Install Healthchecks using pip:
sudo pip3 install healthchecks
  1. Create a new Healthchecks configuration file:
sudo mkdir /etc/healthchecks
sudo touch /etc/healthchecks/default.cfg
  1. Open the configuration file and add the following:
DATABASE_URL='postgres://healthchecks:**your-postgres-password**@localhost/healthchecks'
SITE_ROOT='http://your-domain-name'

Replace your-postgres-password with your own password and your-domain-name with your domain name or subdomain name. Save the file and close it.

Step 3: Create Database and User

  1. Login to PostgreSQL as the root user:
sudo -u postgres psql
  1. Create a new database and user for Healthchecks:
CREATE DATABASE healthchecks;
CREATE USER healthchecks WITH PASSWORD '**your-healthchecks-password**';
GRANT ALL PRIVILEGES ON DATABASE healthchecks TO healthchecks;

Replace your-healthchecks-password with your own password. Exit PostgreSQL:

\q

Step 4: Setup Healthchecks

  1. In your terminal, run the following command to create Healthchecks database tables:
hcdb migrate
  1. Start Healthchecks:
hc start
  1. Check if Healthchecks is running by visiting http://your-domain-name/ping

You should see the message "PONG".

Step 5: Configure Systemd Service

  1. Create a new Systemd service file for Healthchecks:
sudo touch /etc/systemd/system/healthchecks.service
  1. Open the file and add the following:
[Unit]
Description=Healthchecks
After=syslog.target

[Service]
User=root
Group=root
WorkingDirectory=/root/healthchecks
ExecStart=/usr/local/bin/hc runserver
Restart=always

[Install]
WantedBy=multi-user.target
  1. Save the file and close it.

  2. Reload systemd:

sudo systemctl daemon-reload
  1. Enable Healthchecks to run at boot:
sudo systemctl enable healthchecks.service

Conclusion

You have successfully installed Healthchecks on NixOS Latest. You can now configure Healthchecks to monitor your software services and receive alerts when services fail.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!