diff --git a/dockerfiles/prometheus/Dockerfile b/dockerfiles/prometheus/Dockerfile index d4ae09c..9f52211 100644 --- a/dockerfiles/prometheus/Dockerfile +++ b/dockerfiles/prometheus/Dockerfile @@ -1,5 +1,7 @@ FROM prom/prometheus:latest +COPY prometheus.yml.tmpl /etc/prometheus/prometheus.yml.tmpl +COPY entrypoint.sh /entrypoint.sh -COPY prometheus.yaml /etc/prometheus/prometheus.yml +ENV ENABLE_BACKEND_METRICS=false -CMD ["--config.file=/etc/prometheus/prometheus.yml", "--web.enable-remote-write-receiver"] +ENTRYPOINT ["/entrypoint.sh"] diff --git a/dockerfiles/prometheus/entrypoint.sh b/dockerfiles/prometheus/entrypoint.sh new file mode 100755 index 0000000..85bebd5 --- /dev/null +++ b/dockerfiles/prometheus/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ "$ENABLE_BACKEND_METRICS" = "true" ]; then + BACKEND_JOB="- job_name: 'backend'\n metrics_path: '/metrics'\n static_configs:\n - targets: ['backend:5000']" +else + BACKEND_JOB="" +fi + +# Replace placeholder in the template +sed "s|{{BACKEND_JOB}}|$BACKEND_JOB|" /etc/prometheus/prometheus.yml.tmpl > /etc/prometheus/prometheus.yml + +# Start Prometheus +exec /bin/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-remote-write-receiver diff --git a/dockerfiles/prometheus/prometheus.yaml b/dockerfiles/prometheus/prometheus.yml.tmpl similarity index 59% rename from dockerfiles/prometheus/prometheus.yaml rename to dockerfiles/prometheus/prometheus.yml.tmpl index c5b34cc..415b49f 100644 --- a/dockerfiles/prometheus/prometheus.yaml +++ b/dockerfiles/prometheus/prometheus.yml.tmpl @@ -7,7 +7,4 @@ scrape_configs: static_configs: - targets: ['localhost:9090'] - - job_name: 'backend' - metrics_path: '/metrics' - static_configs: - - targets: ['backend:5000'] + {{BACKEND_JOB}}