Prometheus

Prometheus is configured with a single YAML file. Keeping in line with the rest of the project, create a directory for it, outside the project:

mkdir -p ~/volumes/prometheus

Start with a configuration that only scrapes Prometheus itself:

~/volumes/prometheus/prometheus.ymlyaml
global:
  scrape_interval: 15s
  evaluation_interval: 15s
  external_labels:
    environment: dev

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['prometheus:9090']
  • scrape_interval is how often Prometheus fetches metrics, and evaluation_interval how often it checks alerting rules.
  • external_labels are added to everything this Prometheus sends elsewhere, such as alerts, which helps if you ever have more than one.
  • targets is a list of host:port addresses to scrape. Prometheus is reached by its container name, prometheus.

For the metrics data itself, use a Podman volume, which avoids file permission problems, since the container runs as a different user:

podman volume create prometheus-vol

Run the container, attached to the monitoring network, with the configuration directory and data volume mounted, and the web interface on port 9090:

podman run -d --name prometheus --network monitoring-network -p 9090:9090 \
  -v ~/volumes/prometheus:/etc/prometheus:Z \
  -v prometheus-vol:/prometheus \
  docker.io/prom/prometheus:v3.16.0

The :Z on the configuration mount tells Podman to relabel the directory for SELinux, which Fedora and RHEL need, so the container is allowed to read it.

Open http://localhost:9090. Under Status, Target health, you’ll see Prometheus scraping itself. You can check the configuration file for mistakes with promtool, which is included in the image:

podman exec prometheus promtool check config /etc/prometheus/prometheus.yml

Whenever you change the configuration, restart Prometheus to load it:

podman restart prometheus