postgres-exporter.compose.yml50 lines · main
1# Sidecar for the data-plane Postgres. Drop this into the compose project
2# that already runs the data-plane container — NOT into the observability
3# compose. The exporter needs to live next to the database so it can
4# scrape pg_stat_* with low-latency local-socket access; prometheus then
5# scrapes the exporter from across the briven docker network.
6#
7# Wire it in by adding `services:` and `networks:` blocks to your existing
8# data-plane compose, or `docker compose -f data-plane.yml -f
9# postgres-exporter.compose.yml up -d` to merge the two.
10#
11# Required env on the data-plane container (or via .env.local):
12# POSTGRES_EXPORTER_DATA_SOURCE_NAME — read-only DSN. Recommend creating
13# a dedicated `briven_metrics` postgres role with pg_monitor membership
14# so the exporter can read pg_stat_* without superuser:
15# CREATE ROLE briven_metrics LOGIN PASSWORD '<rotated>';
16# GRANT pg_monitor TO briven_metrics;
17#
18# Then DSN looks like:
19# postgresql://briven_metrics:<password>@briven-postgres:5432/postgres?sslmode=disable
20#
21# (The exporter is on the internal docker network; sslmode=disable is
22# fine. If you migrate the data plane to a managed cluster, switch to
23# sslmode=require.)
24
25services:
26 postgres-exporter:
27 image: prometheuscommunity/postgres-exporter:v0.16.0
28 restart: unless-stopped
29 environment:
30 DATA_SOURCE_NAME: ${POSTGRES_EXPORTER_DATA_SOURCE_NAME}
31 # Default collectors are fine for the four-dashboard set (database
32 # size, transactions, deadlocks, longest query). Add explicit
33 # `--collector.<name>` flags here when adding more dashboards.
34 PG_EXPORTER_AUTO_DISCOVER_DATABASES: 'true'
35 PG_EXPORTER_EXCLUDE_DATABASES: 'template0,template1'
36 networks:
37 # Explicit alias: this container lives in its own compose project
38 # (briven-pg-exporter), but the prometheus container scrapes us by
39 # the short name `postgres-exporter`. Docker compose normally
40 # only aliases within its own project; we need a cross-project
41 # alias on the shared dokploy-network so prometheus can resolve.
42 dokploy-network:
43 aliases:
44 - postgres-exporter
45 labels:
46 - 'briven_logs=true'
47
48networks:
49 dokploy-network:
50 external: true