Running Prometheus on Home Assistant

Hello! :wave:

I’ve been working on setting up a monitoring solution for my Home Assistant setup. Configuring InfluxDB and Grafana was pretty straightforward. Now, I want to add Prometheus to the mix. However, there isn’t a Prometheus add-on available for Home Assistant.

To address this, I decided to use Portainer, which installed without any issues. I created a stack using the Docker Compose file shared below. The stack started up, but I encountered some confusion regarding how the volumes are being handled.

Although protection mode is disabled on the add-on, Portainer isn’t mounting the existing folder. Instead, it’s trying to create a new folder in /data/compose/20, with the number increasing each time I attempt to create the stack.

If I let Portainer create the volumes, the stack is created successfully, but no folders are generated on the local file system.

I realize this topic covers multiple aspects, but I’d really like to hear your thoughts on this.

Thanks in advance!

And here’s my current Docker Compose configuration:

volumes:
    prometheus_data: {}
    prometheus_etc: {}

services:
  prometheus:
    image: prom/prometheus:2.54.1
    container_name: prometheus
    volumes:
#    - /homeassistant/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -> does not work
      - prometheus_etc:/etc/prometheus
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    restart: unless-stopped
    expose:
      - 9090
    ports:
      - 9090:9090
    labels:
      org.label-schema.group: "monitoring"

You have 2 options:

  • Use a docker volume, as you mention
  • Use an existing folder on the filesystem of HAOS, in which case the volume definitions should be something line “/mnt/data/supervisor/homeassistant/prometheus/etc: /etc/prometheus”. I think you first have to create the directories, so “/config/prometheus/etc” from inside HA.

First I created /mnt/data/supervisor/homeassistant/prometheus/etc on HAOS but it did not get mounted and I think because there is no ./ in the beginning which tells to docker to look for localhost, right?

Then I realized that Portainer is actually looking for /data/compose/ which is mounted read-only.

Am I missing an option on Portainer?

Hey, did you get anywhere with this epic quest?

Yes, I just did! A moment ago I was reading Tutorial: add Homebridge to Hass.io using Portainer where I see volume is defined as “/mnt/data/supervisor/homeassistant/homebridge” which reminded me @koying’s response that I tried again and it worked :slight_smile:

Below you may see the docker-compose. Clearly I was doing something wrong.
Not sure what it was but finally I understood how volume path is treated.

services:
  prometheus:
    image: prom/prometheus:v2.36.2
    container_name: prometheus
    user: root
    volumes:
      - /mnt/data/supervisor/homeassistant/prometheus/etc:/etc/prometheus
      - /mnt/data/supervisor/homeassistant/prometheus/data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=200h'
      - '--web.enable-lifecycle'
    restart: unless-stopped
    expose:
      - 9090
    ports:
      - 9090:9090
    labels:
      org.label-schema.group: "monitoring"
1 Like