This project was inspired by this blog post by IPngNetworks and Mastodon Setup with Docker Compose by raeffs. In his blog, Pim discusses how he uses Prometheus and Grafana to monitor his Mastodon instance. Everything used is FOSS and available as a container, so I was keen to get it all working in a docker compose stack.
- Clone the repository
git clone https://github.com/luc122c/mastodon-metrics.git
- Create a
.env
file and set up your credentials
ADMIN_USER='admin'
ADMIN_PASSWORD='pleasechangeme'
ALLOW_SIGN_UP=false
- Create a volume for Grafana with the command
docker volume create grafana-data
- Run
docker compose up
and wait for it all to load - Visit
localhost:3000
and login. You should see the 'Mastodon Stats' dashboard available. - Configure Mastodon to log StatsD events to your server with the following environment variable. If Mastodon is running on a separate machine, replace
localhost
with the IP address of that machine.
STATSD_ADDR='localhost:9125'
- Restart Mastodon so that the changes take effect. Data should start to flow into the dashboard.
I've commented out some ports that don't need to be exposed for it to work. You can open 9102
on exporter
to see the raw data and 9090
on prometheus
to see the the Prometheus output.
One other thing I've changed from IPngNetworks' config is the UID of the datasource. The existing value wasn't working so it is now sausage
.
Below are the links to the software, configuration files and articles that make this work.
- Mastodon - Part 3 - statsd and Prometheus - The brains of the operation
- Mastodon Setup with Docker Compose - Thank you for getting me into Mastodon and for inspiring me to make this stack
- Mastodon StatsD documentation
- StatsD to Prometheus metrics exporter
- Prometheus - Monitoring and Database
- Grafana - data visualization platform
- Mastodon Stats Grafana dashboard - Makes the pretty visuals
- StatsD Exporter mapping configuration file - Speaks Mastodon and Prometheus at the same time
- Metrics with Prometheus StatsD Exporter and Grafana - Thank you for helping me configure the automatic provisioning of the dashboard and datasource.
- Grafana Data Source on Startup - Thank you for helping me configure the automatic provisioning of the dashboard and datasource.