Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ services:
- '--path.rootfs=/host'
pid: host
restart: unless-stopped
pushgateway:
image: prom/pushgateway:latest
restart: unless-stopped
ports:
- 9091:9091

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to expose port 9091? its so metrics can make it to the container?

what if we put this container behind nginx?

you can test this locally, with 3 containers

  1. pushgateway with no port exposed
  2. nginx container that routes stuff to the pushgateway, if someone visits the nginx port + a path like /pushgateway
  3. a python file to push some data to this nginx path

for an intro on nginx see
https://www.youtube.com/watch?v=HWrhSpN4ar0&t=4s


volumes:
alertmanager-data:
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ services:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- portainer_data:/data
pushgateway:
image: prom/pushgateway:latest
restart: unless-stopped

volumes:
alertmanager-data:
Expand Down
3 changes: 3 additions & 0 deletions prometheus/prometheus.federate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ scrape_configs:
- targets:
- prometheus-clark-sshtunnel:9090
- prometheus-poweredge:9090
- job_name: 'pushgateway'
static_configs:
- targets: ['pushgateway:9091']

alerting:
alertmanagers:
Expand Down
9 changes: 9 additions & 0 deletions pushgateway-nginx-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.12-slim

WORKDIR /app

RUN pip install --no-cache-dir prometheus-client

COPY push_metrics.py .

CMD ["python", "push_metrics.py"]
19 changes: 19 additions & 0 deletions pushgateway-nginx-test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
pushgateway:
image: prom/pushgateway:latest
command:
- '--web.external-url=http://localhost:80/pushgateway/'

nginx:
image: nginx:alpine
ports:
- '80:80'
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- pushgateway

pusher:
build: .
depends_on:
- nginx
11 changes: 11 additions & 0 deletions pushgateway-nginx-test/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
listen 80;

location = /pushgateway {
return 301 /pushgateway/;
}

location /pushgateway/ {
proxy_pass http://pushgateway:9091;
}
}
18 changes: 18 additions & 0 deletions pushgateway-nginx-test/push_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway

registry = CollectorRegistry()

metric = Gauge(
"nginx_pushgateway_test",
"Metric sent through the Nginx proxy",
registry=registry,
)
metric.set(50)

push_to_gateway(
"http://nginx/pushgateway",
job="nginx_proxy_test",
registry=registry,
)

print("successfully pushed metric")