From 9422d8b19fdcd5bb245371c61c7e47ccb17c6dca Mon Sep 17 00:00:00 2001 From: yanboer Date: Fri, 26 May 2023 14:59:07 +0800 Subject: [PATCH 1/4] adjust pg_replication_slots metrics --- cmd/postgres_exporter/queries.go | 5 +++-- collector/replication_slots.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/postgres_exporter/queries.go b/cmd/postgres_exporter/queries.go index 14c14b4f8..7b031a500 100644 --- a/cmd/postgres_exporter/queries.go +++ b/cmd/postgres_exporter/queries.go @@ -112,8 +112,9 @@ var queryOverrides = map[string][]OverrideQuery{ { semver.MustParseRange(">=10.0.0"), ` - SELECT slot_name, database, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) - FROM pg_replication_slots + SELECT slot_name, database, active, + (case pg_is_in_recovery() when 't' then pg_last_wal_receive_lsn() - restart_lsn else pg_current_wal_lsn() - restart_lsn end) as pg_wal_lsn_diff + FROM pg_replication_slots; `, }, }, diff --git a/collector/replication_slots.go b/collector/replication_slots.go index a9cad77df..a7459cb2c 100644 --- a/collector/replication_slots.go +++ b/collector/replication_slots.go @@ -53,9 +53,9 @@ var pgReplicationSlot = map[string]*prometheus.Desc{ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error { rows, err := db.QueryContext(ctx, - `SELECT + `SELECT slot_name, - pg_current_wal_lsn() - '0/0' AS current_wal_lsn, + (case pg_is_in_recovery() when 't' then pg_last_wal_receive_lsn() - '0/0' else pg_current_wal_lsn() - '0/0' end) as current_wal_lsn, coalesce(confirmed_flush_lsn, '0/0') - '0/0', active FROM From 925a7826272c4986064d8a104771673f8885ac8d Mon Sep 17 00:00:00 2001 From: yanboer Date: Mon, 5 Jun 2023 13:33:07 +0800 Subject: [PATCH 2/4] add web.listenAddress param, from --web.listenAddress or PG_EXPORTER_WEB_LISTEN_ADDRESS env get value --- cmd/postgres_exporter/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/postgres_exporter/main.go b/cmd/postgres_exporter/main.go index efa96738b..fc4760371 100644 --- a/cmd/postgres_exporter/main.go +++ b/cmd/postgres_exporter/main.go @@ -38,6 +38,7 @@ var ( Config: &config.Config{}, } + listenAddress = kingpin.Flag("web.listenAddress", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").Strings() configFile = kingpin.Flag("config.file", "Postgres exporter configuration file.").Default("postgres_exporter.yml").String() webConfig = kingpinflag.AddFlags(kingpin.CommandLine, ":9187") metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").Envar("PG_EXPORTER_WEB_TELEMETRY_PATH").String() @@ -156,6 +157,8 @@ func main() { http.HandleFunc("/probe", handleProbe(logger, excludedDatabases)) + // set WebListenAddresses from PG_EXPORTER_WEB_LISTEN_ADDRESS env or --web.listenAddress param + webConfig.WebListenAddresses = listenAddress srv := &http.Server{} if err := web.ListenAndServe(srv, webConfig, logger); err != nil { level.Error(logger).Log("msg", "Error running HTTP server", "err", err) From de88f97aec7272e900054e24a4660594cae63c13 Mon Sep 17 00:00:00 2001 From: yanbo <48461101+yanboer@users.noreply.github.com> Date: Mon, 5 Jun 2023 14:21:57 +0800 Subject: [PATCH 3/4] Update README.md Signed-off-by: yanbo <48461101+yanboer@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b54b4b63c..04b226ac0 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ auth_modules: To build the Docker image: make promu - promu crossbuild -p linux/amd64 -p linux/armv7 -p linux/amd64 -p linux/ppc64le + promu crossbuild -p linux/amd64 -p linux/armv7 -p linux/arm64 -p linux/ppc64le make docker This will build the docker image as `prometheuscommunity/postgres_exporter:${branch}`. From a2a4f7033b7e7532ff7e441f6770b6788dccc8a7 Mon Sep 17 00:00:00 2001 From: yanbo <48461101+yanboer@users.noreply.github.com> Date: Mon, 5 Jun 2023 14:49:38 +0800 Subject: [PATCH 4/4] Update README.md Signed-off-by: yanbo <48461101+yanboer@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 04b226ac0..450be3347 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ This will build the docker image as `prometheuscommunity/postgres_exporter:${bra * `web.systemd-socket` Use systemd socket activation listeners instead of port listeners (Linux only). Default is `false` -* `web.listen-address` +* `web.listenAddress` Address to listen on for web interface and telemetry. Default is `:9187`. * `web.config.file`