Skip to content

Commit

Permalink
Issue #65: prometheus dynamic config
Browse files Browse the repository at this point in the history
  • Loading branch information
SonOfLope committed Nov 1, 2024
1 parent 5b03300 commit 1791566
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions dockerfiles/prometheus/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 13 additions & 0 deletions dockerfiles/prometheus/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ scrape_configs:
static_configs:
- targets: ['localhost:9090']

- job_name: 'backend'
metrics_path: '/metrics'
static_configs:
- targets: ['backend:5000']
{{BACKEND_JOB}}

0 comments on commit 1791566

Please sign in to comment.