Running Healthchecks - A Cron Job Monitoring Service - In Docker 🌱

What is Healthchecks?

Healthchecks is a cron job monitoring service. It listens for HTTP requests and email messages ("pings") from your cron jobs and scheduled tasks ("checks"). When a ping does not arrive on time, Healthchecks sends out alerts.

Healthchecks comes with a web dashboard, API, 25+ integrations for delivering notifications, monthly email reports, WebAuthn 2FA support, team management features: projects, team members, read-only access. -https://github.com/healthchecks/healthchecks

Installing Docker

  1. Log into the Linux based device
  2. Run the following commands in the terminal
    # install prerequisites
    sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
    # add docker gpg key
    curl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -
    # add docker software repository
    sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release) $(lsb_release -cs) stable"
    # install docker
    sudo apt install docker-ce docker-compose containerd.io -y
    # enable and start docker service
    sudo systemctl enable docker && sudo systemctl start docker
    # add the current user to the docker group
    sudo usermod -aG docker $USER
    # reauthenticate for the new group membership to take effect
    su - $USER

Running the Healthchecks Container

  1. Now that Docker is installed, run the following commands to setup the Healthchecks Docker container and run it
    # create working directories
    mkdir ~/docker/postresql -p && mkdir ~/docker/healthchecks -p
    # create containers network
    docker network create containers
    # download the base configuration
    wget -O ~/docker/healthchecks/.env https://raw.githubusercontent.com/healthchecks/healthchecks/master/docker/.env.example
    # generate a 32 character random string
    head /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9' | head -c 32
    # copy the output string to the clipboard
    # edit the .env file
    nano ~/docker/healthchecks/.env
  2. Scroll through the .env file, updating at least the key/value pairs listed below

    ALLOWED_HOSTS=*
    ---
    DB=postgres
    DB_HOST=postgres
    DB_NAME=healthchecks
    DB_PASSWORD=He@lt4Ch3ck$!
    DB_USER=healthchecks_rw
    ---
    DEFAULT_FROM_EMAIL=healthchecks@i12bretro.local
    ---
    EMAIL_HOST=smtp.i12bretro.local
    EMAIL_HOST_PASSWORD=
    EMAIL_HOST_USER=
    EMAIL_PORT=25
    EMAIL_USE_TLS=False
    EMAIL_USE_VERIFICATION=False
    ---
    SECRET_KEY=<% random string from clipboard %>

  3. Press CTRL+W and search for localhost
  4. Update all references to localhost with the DNS or IP address of the docker host (ie SITE_ROOT=http://localhost:8000 -> http://ubuntuserver.local:8000)
  5. Press CTRL+O, Enter, CTRL+X to write the changes to .env
  6. Continue with the following commands in terminal
    # set owner of working directories
    sudo chown "$USER":"$USER" ~/docker -R
    # run the postgresql docker container
    docker run -d --name postgres -e POSTGRES_USER=healthchecks_rw -e POSTGRES_PASSWORD='He@lt4Ch3ck$!' -e POSTGRES_DB=healthchecks -v /home/$USER/docker/postresql:/var/lib/postgresql/data --network containers --restart=unless-stopped postgres
    # run the healthchecks container
    docker run -d --name healthchecks --env-file ~/docker/healthchecks/.env -p 8000:8000 --network containers --restart=unless-stopped healthchecks/healthchecks
    # connect to healthchecks container shell
    docker exec -ti healthchecks /bin/bash
    # create an admin user
    /opt/healthchecks/manage.py createsuperuser
    # enter an email address
    # enter and confirm a password
    # exit the container shell
    exit
  7. Open a web browser and navigate to http://DNSorIP:8000
  8. Login with the admin account created earlier
  9. Welcome to HealthChecks

Documentation: https://hub.docker.com/r/healthchecks/healthchecks