I have simple needs:
- How many people are visiting
- When are they visiting
- What are they visiting
- If they’re referred from another site, which
I don’t want to know anything else, nor do I want to give any of my visitor details to Google. When I started looking into alternatives I came across It’s not me, Google, it’s you - from GA to Fathom by Jeff Geerling. Those who work with Ansible, may recognize him for his Ansible roles or his book (Ansible for DevOps). Both are highly recommended.
As expected Jeff’s solution includes an Ansible role to install Fathom on an existing system. This works great if you’re dedicating a system, but using a shared system I prefer to host my services as containers, with nginx proxying.
These are the steps I took to get fathom up and running in a container for my sites.
Starting with a
docker-compose.yml, even though this is a single service and a
relatively simple one I find that creating a
docker-compose.yml file helps to
document the configuration, allows for easy rebuilding, and container
interaction. Plus I don’t have to remember all the command line switches.
version: "3.4" services: fathom: image: usefathom/fathom:latest restart: unless-stopped ports: - "8081:8080" volumes: - type: bind source: ./.env target: /app/.env read_only: true
The Fathom server runs on port
8080, and as this port is popular, and likely
to conflict, this configuration uses port
8081. Of course the port number can be
any available port.
Fathom supports configuration through a
.env file, but doesn’t seem to pull
the values directly from the environment. I created a
.env file alongside the
docker-compose.yml file for docker to load. The compose file mounts the
/app so that
fathom cli itself will use it.
FATHOM_GZIP=true FATHOM_DEBUG=true FATHOM_DATABASE_DRIVER="postgres" FATHOM_DATABASE_NAME="fathom" FATHOM_DATABASE_USER="fathom" FATHOM_DATABASE_PASSWORD="" FATHOM_DATABASE_HOST="172.18.0.1" FATHOM_DATABASE_SSLMODE="disable" FATHOM_SECRET="must not leave this in public"
I have a shared PostgreSQL instance for all sites. Being
able to use it as the data store is a huge bonus. The
setting points to the docker IP address that’s used to access the host system.
This way all communication to the database is within the host.
Now that the application is configured, create a specific database to hold the fathom data. Make sure the database name, user name and password match those in the application configuration.
createdb fathom psql fathom
Now create the
fathom user, and update that database so that the
is the owner.
create user fathom; alter database fathom owner to fathom;
fathom starts it will apply migrations to the database automatically so
that the structure is in sync with the applications requirements.