Skip to content
Merged
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,12 @@ Cutover can be done atomically with multiple PgDog containers because `RELOAD` d
📘 **[Metrics](https://docs.pgdog.dev/features/metrics/)**

PgDog exposes both the standard PgBouncer-style admin database, an OpenMetrics endpoint and can push metrics to an OTEL endpoint. The admin database isn't 100% compatible,
so we recommend you use either OpenMetrics or OTEL ingestion for monitoring. Example Datadog configuration and dashboard are [included](examples/datadog).
so we recommend you use either OpenMetrics or OTEL ingestion for monitoring.

We include two examples:

- [Datadog configuration and dashboard](examples/datadog)
- [Graphana + Prometheus configuration and dashboard](examples/grafana_prometheus)


## Running PgDog locally
Expand Down
32 changes: 32 additions & 0 deletions examples/grafana_prometheus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Grafana + Prometheus

Pushes PgDog metrics to Prometheus over OTLP and visualizes them in Grafana.

```
pgdog --OTLP push (every 5s)--> prometheus <-- grafana
```

## Push, not scrape

PgDog's OTEL exporter (`[otel]` block in `pgdog.toml`) POSTs OTLP JSON to
Prometheus's built-in OTLP receiver, enabled with `--web.enable-otlp-receiver`
(see `docker-compose.metrics.yml`). `prometheus.yml` has no scrape jobs —
Prometheus only ingests what PgDog pushes.

Metric names are prefixed with `pgdog_` (via `namespace` in `[otel]`); OTLP
attributes become Prometheus labels.

## Grafana provisioning

`provisioning/grafana/` is mounted into `/etc/grafana/provisioning/`, so the
Prometheus datasource and the PgDog dashboard show up automatically on first
boot.

## Running

```sh
docker compose up
```

- Prometheus — http://127.0.0.1:9090
- Grafana — http://127.0.0.1:3000 (admin / admin), _PgDog_ folder
31 changes: 31 additions & 0 deletions examples/grafana_prometheus/docker-compose.metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
prometheus:
image: prom/prometheus:latest
command:
- --config.file=/etc/prometheus/prometheus.yml
- --web.enable-otlp-receiver
volumes:
- ./provisioning/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- 9090:9090

grafana:
image: grafana/grafana:latest
depends_on:
- prometheus
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: admin
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
volumes:
- ./provisioning/grafana/datasources:/etc/grafana/provisioning/datasources
- ./provisioning/grafana/dashboards:/etc/grafana/provisioning/dashboards
- grafana_data:/var/lib/grafana
ports:
- 3000:3000

volumes:
prometheus_data:
grafana_data:
45 changes: 45 additions & 0 deletions examples/grafana_prometheus/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
include:
- ./docker-compose.metrics.yml

services:
db0:
image: postgres:17
environment:
POSTGRES_PASSWORD: postgres
ports:
- 6000:5432
volumes:
- shard_0:/var/lib/postgresql/data
db1:
image: postgres:17
environment:
POSTGRES_PASSWORD: postgres
ports:
- 6001:5432
volumes:
- shard_1:/var/lib/postgresql/data
db2:
image: postgres:17
environment:
POSTGRES_PASSWORD: postgres
ports:
- 6002:5432
volumes:
- shard_2:/var/lib/postgresql/data

pgdog:
image: ghcr.io/pgdogdev/pgdog:main
depends_on:
- db0
- db1
- db2
volumes:
- ./pgdog.toml:/pgdog/pgdog.toml
- ./users.toml:/pgdog/users.toml
ports:
- 6432:6432

volumes:
shard_0:
shard_1:
shard_2:
29 changes: 29 additions & 0 deletions examples/grafana_prometheus/pgdog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# PgDog configuration.
#

[general]
host = "0.0.0.0"

[otel]
endpoint = "http://prometheus:9090/api/v1/otlp/v1/metrics"
namespace = "pgdog_"
push_interval = 5000

[[databases]]
name = "postgres"
host = "db0"
port = 5432
shard = 0

[[databases]]
name = "postgres"
host = "db1"
port = 5432
shard = 1

[[databases]]
name = "postgres"
host = "db2"
port = 5432
shard = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: 1

providers:
- name: PgDog
orgId: 1
folder: PgDog
type: file
disableDeletion: false
editable: true
updateIntervalSeconds: 30
options:
path: /etc/grafana/provisioning/dashboards
Loading
Loading