How to make Prometheus setup via docker-compose reads a certain prometheus.yml file

265 views
Skip to first unread message

Shutima Potivorakun

unread,
Apr 9, 2021, 6:22:18 AM4/9/21
to Prometheus Users
Hello all,

I am new to Prometheus and docker-compose. I have a project structure with docker-compose.yml file that setup Prometheus and Grafana:
"/prometheus-grafana/prometheus/docker-compose.yml"

version: '3'

services:
prometheus:
image: prom/prometheus:v2.21.0
ports:
- 9000:9090
volumes:
- ./prometheus:/etc/prometheus
- prometheus-data:/prometheus
command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml

grafana:
image: grafana/grafana:$GRAFANA_VERSION
environment:
GF_SECURITY_ADMIN_USER: $GRAFANA_ADMIN_USER
GF_SECURITY_ADMIN_PASSWORD: $GRAFANA_ADMIN_PASSWORD
ports:
- 3000:3000
volumes:
- grafana-storage:/var/lib/grafana
depends_on:
- prometheus
networks:
- internal

networks:
internal:

volumes:
prometheus-data:
grafana-storage:

I just added more config in "/prometheus-grafana/prometheus/prometheus/prometheus.yml" like this, the part that I added is yellow highlighted:

global:
scrape_interval: 30s
scrape_timeout: 10s

rule_files:
- alert.yml

scrape_configs:
- job_name: services
metrics_path: /metrics
static_configs:
- targets:
- 'prometheus:9090'
- 'idonotexists:564'
- job_name: myapp
scrape_interval: 10s
static_configs:
- targets:
- localhost:2112

I started Prometheus by running: "docker-compose up -d", I got to Prometheus on "http://localhost:9000/graph" but I don't see the new config I added to "prometheus.yml", in docker-compose.yml file, there is a line "command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml" Am I supposed to change this to refers to the path of my another Prometheus.yml in my project?

Thank you in advance.

Rgds,
Shutima Potivorakun

sayf.eddi...@gmail.com

unread,
Apr 9, 2021, 6:32:37 AM4/9/21
to Prometheus Users
If you have an error in the config file, prometheus will just ignore the new config and stays with the old one, check the logs of the container and make sure there are not errors

Shutima Potivorakun

unread,
Apr 12, 2021, 5:50:46 AM4/12/21
to Prometheus Users
Hello, I checked docker-compose log, I don't see any error but I saw that it loads prometheus.yml file from here and NOT from my project. I should change this directory to load instead from my project and not from /etc/prometheus ?

prometheus_1  | 2021-04-12T09:34:28.726678910Z level=info ts=2021-04-12T09:34:28.726Z caller=main.go:850 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
Reply all
Reply to author
Forward
0 new messages