高级 PostgreSQL 和 Pgbouncer 指标导出器 (用于 Prometheus)
Advanced PostgreSQL & pgBouncer metrics exporter for Prometheus
PG Exporter brings ultimate monitoring experience to your PostgreSQL with declarative config, dynamic planning, and customizable collectors. It provides 600+ metrics and ~3K time series per instance, covers everything you'll need for PostgreSQL observability.
timescaledb, citus, pg_stat_statements, pg_wait_sampling,...sslmode=disable when omittedAlso support PG 9.x with legacy config bundle.
RPM / DEB / Tarball available in the GitHub release page, and Pigsty's YUM / APT Infra Repo.
To run this exporter, you need to pass the postgres/pgbouncer URL via env or arg:
PG_EXPORTER_URL='postgres://user:pass@host:port/postgres' pg_exporter
curl http://localhost:9630/metrics # access metricsThere are built-in metrics such as pg_up, pg_version, pg_in_recovery, pg_exporter_build_info, and exporter self-metrics under pg_exporter_* (disable with --disable-intro).
All other metrics are defined in the pg_exporter.yml config file.
There are two monitoring dashboards in the monitor/ directory.
You can use Pigsty to monitor existing PostgreSQL cluster or RDS, it will setup pg_exporter for you.
…Parameters could be given via command-line args or environment variables.
| CLI Arg | Environment Variable | Default Value |
|---|---|---|
--url |
PG_EXPORTER_URL |
postgresql:///?sslmode=disable |
--config |
PG_EXPORTER_CONFIG |
pg_exporter.yml |
--label |
PG_EXPORTER_LABEL |
|
--tag |
PG_EXPORTER_TAG |
|
--auto-discovery |
PG_EXPORTER_AUTO_DISCOVERY |
true |
--disable-cache |
PG_EXPORTER_DISABLE_CACHE |
false |
--fail-fast |
PG_EXPORTER_FAIL_FAST |
false |
--exclude-database |
PG_EXPORTER_EXCLUDE_DATABASE |
|
--include-database |
PG_EXPORTER_INCLUDE_DATABASE |
|
--namespace |
PG_EXPORTER_NAMESPACE |
pg|pgbouncer |
--connect-timeout |
PG_EXPORTER_CONNECT_TIMEOUT |
100 |
--dry-run |
false |
|
--explain |
false |
|
--log.level |
info |
|
--log.format |
logfmt |
|
--web.listen-address |
:9630 |
|
--web.config.file |
"" |
|
--web.telemetry-path |
PG_EXPORTER_TELEMETRY_PATH |
/metrics |
--url / PG_EXPORTER_URL is not provided, pg_exporter falls back to a local-first default URL: postgresql:///?sslmode=disable.sslmode is not explicitly set in the URL, pg_exporter injects sslmode=disable by default.pg_exporter and PostgreSQL/PgBouncer on the same machine), where loopback TLS adds overhead with little practical gain.sslmode explicitly in the connection URL (for example: sslmode=require, verify-ca, verify-full).PG Exporter provides a rich set of HTTP endpoints:
Here are pg_exporter REST APIs
…To build a static stand-alone binary for docker scratch
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o pg_exporterOr download the latest prebuilt binaries from release pages.
We also have pre-packaged RPM / DEB packages in the Pigsty Infra Repo
You can find pre-built amd64/arm64 docker images here: pgsty/pg_exporter
Build a local development image from the canonical Dockerfile:
make docker
# Override the image repository when needed:
make docker DOCKER_REPO=example/pg_exporterMulti-architecture release images are built by GoReleaser together with the other release artifacts.
Redhat rpm and Debian/Ubuntu deb packages are made with nfpm for x86/arm64:
/usr/bin/pg_exporter: the pg_exporter binary./etc/pg_exporter.yml: the config file/usr/lib/systemd/system/pg_exporter.service: systemd service file/etc/default/pg_exporter: systemd service envs & optionsWhich is also available on Pigsty's Infra Repo.
Configs lie in the core of pg_exporter. Actually, this project contains more lines of YAML than go.
pg_exporter.ymlconfig/doc.ymldocs/design/histogram.mdlegacy/ (legacy/README.md)Current pg_exporter ships 58 collector definition files in config/. They are merged into pg_exporter.yml by make conf.
| File | Collector namespace(s) | Scope / requirement |
|---|---|---|
| 0000-doc.yml | config reference | YAML schema and collector authoring guide; not an installed collector |
| 0110-pg.yml | pg |
PostgreSQL basic information, with primary and replica branches |
| 0120-pg_meta.yml | pg_meta |
PostgreSQL cluster metadata; PG13+ includes primary_conninfo |
| 0130-pg_setting.yml | pg_setting |
Shared PostgreSQL settings and capacity limits |
| 0210-pg_repl.yml | pg_repl |
Replication sender statistics |
| 0220-pg_sync_standby.yml | pg_sync_standby |
Synchronous standby status |
| 0230-pg_downstream.yml | pg_downstream |
Downstream replication client counts |
| 0240-pg_slot.yml | pg_slot |
Replication slots; PG16+ branches also work on standbys, and PG17+ recognizes the PG19 idle_timeout invalidation reason |
| 0250-pg_recv.yml | pg_recv |
Replica WAL receiver metrics; PG13+ branch recognizes the PG19 connecting status |
| 0260-pg_sub.yml | pg_sub |
Subscription stats; PG19 branch covers table/sequence sync errors and logical replication conflict counters |
| 0270-pg_origin.yml | pg_origin |
Replication origin status; disabled by default and may need extra privileges |
| 0300-pg_io.yml | pg_io |
pg_stat_io metrics for PG16+, with PG18+ branch |
| 0310-pg_size.yml | pg_size |
Database, WAL, and log size metrics |
| 0320-pg_archiver.yml | pg_archiver |
Archiver process statistics |
| 0330-pg_bgwriter.yml | pg_bgwriter |
Background writer statistics, with PG17+ branch |
| 0331-pg_checkpointer.yml | pg_checkpointer |
Checkpointer statistics, with PG18+ num_done and slru_written metrics |
| 0340-pg_ssl.yml | pg_ssl |
SSL client connection counts |
暂无开放 Issues,或尚未同步最近议题。