Deploying Prometheus in Docker

Prometheus is an open-source systems monitoring and alerting toolkit.

Docker Deployment

First we need to create the prometheus.yml configuration file. This file stores all the necessary info for scraping jobs, etc. We will be configuring it later so first create the directory for Prometheus.

mkdir /opt/containers/prometheus

Then create the prometheus.yml file.

touch /opt/containers/prometheus/prometheus.yml

Once the prometheus.yml file is created we can deploy Prometheus in docker.

Prometheus does not need a lot of environment configuration for the container as most of it is handled in the prometheus.yml file.

curl -o /opt/containers/prometheus/prometheus-compose.yml

Now deploy Prometheus.

docker-compose -f /opt/containers/prometheus/prometheus-compose.yml up -d

Prometheus should now be running. However its not yet configured. In order to get any data from Prometheus we need to deploy exporters for it to scrape.

Part of the docker ps output.

Exporter Setup

Check out my blog posts about Prometheus Exporters to get started!

  • Expanding Pi-Hole Stats with Prometheus
    The other day I came across a Prometheus Exporter for Pi-hole (found in a comment on /r/pihole) that gives WAY more stats/data compared to the InfluxDB script I posted about awhile back. With this exporter, I was able to setup a more detailed dashboard. Now currently I only have this setup for a single instance… Read More »Expanding Pi-Hole Stats with Prometheus
  • Transmission Metrics in Grafana
    If you use Transmission as your download client, you can use a metrics exporter for Prometheus to ingest info into Grafana to display. You’ll also want to make sure Prometheus is setup and running or else this won’t work! SSH to your docker host that is running Prometheus and edit the prometheus.yml configuration file by adding the following: Save and close prometheus.yml. Now… Read More »Transmission Metrics in Grafana

You can expand off these with other exporters. Just be sure to add a job config to your prometheus.yml file and restart Prometheus!

Grafana Setup

Prometheus is super easy to add to Grafana as it does not, by default, require any auth.

  1. Login to Grafana
  2. Hover over the settings cog
  3. Click Data Sources
  4. Then click ‘Add data source”
  5. Click Prometheus
  6. Enter ‘prometheus:9090’ in the URL field
  7. Click Save & Test

If you get an error make sure Prometheus was joined to the docker network ‘InfluxNet’. You can run `docker inspect prometheus-prometheus-1′ on your docker host to verify.

Look for “NetworkMode”: “InfluxNet”, in the output.

Useful links