postgres-exporter.compose.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. services:
  25. postgres-exporter:
  26. image: prometheuscommunity/postgres-exporter:v0.16.0
  27. restart: unless-stopped
  28. environment:
  29. DATA_SOURCE_NAME: ${POSTGRES_EXPORTER_DATA_SOURCE_NAME}
  30. # Default collectors are fine for the four-dashboard set (database
  31. # size, transactions, deadlocks, longest query). Add explicit
  32. # `--collector.<name>` flags here when adding more dashboards.
  33. PG_EXPORTER_AUTO_DISCOVER_DATABASES: 'true'
  34. PG_EXPORTER_EXCLUDE_DATABASES: 'template0,template1'
  35. networks:
  36. # Explicit alias: this container lives in its own compose project
  37. # (briven-pg-exporter), but the prometheus container scrapes us by
  38. # the short name `postgres-exporter`. Docker compose normally
  39. # only aliases within its own project; we need a cross-project
  40. # alias on the shared dokploy-network so prometheus can resolve.
  41. dokploy-network:
  42. aliases:
  43. - postgres-exporter
  44. labels:
  45. - 'briven_logs=true'
  46. networks:
  47. dokploy-network:
  48. external: true