From 1791566764f9b0617d86eff2dadfbd225a4d619b Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Fri, 1 Nov 2024 14:16:24 -0400 Subject: [PATCH] Issue #65: prometheus dynamic config --- dockerfiles/prometheus/Dockerfile | 6 ++++-- dockerfiles/prometheus/entrypoint.sh | 13 +++++++++++++ .../{prometheus.yaml => prometheus.yml.tmpl} | 5 +---- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100755 dockerfiles/prometheus/entrypoint.sh rename dockerfiles/prometheus/{prometheus.yaml => prometheus.yml.tmpl} (59%) 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}}