VPS 4: Deploying a real time stats dashboard

Glances + Caddy's HTTP Basic Authentication

VPS 4: Deploying a real time stats dashboard

This is the fourth part of my VPS blog series .

Glances with Docker Compose

It’s time to deploy our first project: a real-time server stats dashboard. We’ll use Glances , a lightweight Python-based tool.

  1. Create a new project: Let's call it vps-stats. By default, it will be in an Environment: Production.

    coolify-new-project

  2. Add resource: Choose Docker Compose.

    coolify-new-resource

  3. Paste the glances YAML : You need to adapt it a little bit for Coolify. Here's the final working version:

    version: '3'
    services:
      monitoring:
        image: nicolargo/glances:latest
        restart: always
        pid: host
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - /etc/os-release:/etc/os-release:ro
        environment:
          - "GLANCES_OPT=-w"
    
    coolify-docker-compose
  4. Configure domain and deploy: stats.yourdomain.com:61208

    coolify-domain-config

Once live, visit stats.yourdomain.com to see your dashboard

stats

Secure with Caddy Basic Auth

Why?

  • The dashboard exposes server metrics that may or may not be sensitive but shouldn't be public.
  • It is a nice exercise.

Generate hashed password

Caddy has a built-in command caddy hash-password

caddy hash-password
	[-p, --plaintext <password>]
	[-a, --algorithm <name>]

If for any reason you have Caddy installed in your machine, you can run it there. I don't have Caddy on mine, but the VPS has Docker installed on it, so we can:

  • Log into the VPS:
    • ssh user-with-sudo@yourdomain.com
  • Spin up a Docker container:
    • sudo docker run --rm caddy caddy hash-password -p "yoursupersecretpassword"
  • Copy the bcrypt hash output (starts with $2b$).
  • Logout.

Add to the service docker-compose.yml the caddy label

Now it should look something like this:

version: '3'
services:
  monitoring:
    image: 'nicolargo/glances:latest'
    restart: always
    pid: host
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'
      - '/etc/os-release:/etc/os-release:ro'
    environment:
      - GLANCES_OPT=-w
    labels:
      - 'caddy_0.basicauth.0_YOURUSERHERE=YOURHASHEDPASSWORDHERE'
caddy-basicauth

Restart the service and visit stats.yourdomain.com. You should now see an auth prompt.

login-form

Next lecture

VPS 5: Deploying a Full-Stack App