From 0d443d8372dd76d5857c8e45668d06c1f5116dab Mon Sep 17 00:00:00 2001 From: Russ Garrett Date: Fri, 1 Nov 2019 17:50:22 +0000 Subject: [PATCH] Export pg_stat_archiver metrics These are useful for knowing if WAL archiving is working successfully. --- cmd/postgres_exporter/postgres_exporter.go | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/postgres_exporter/postgres_exporter.go b/cmd/postgres_exporter/postgres_exporter.go index 8b65d46b7..9546f031b 100644 --- a/cmd/postgres_exporter/postgres_exporter.go +++ b/cmd/postgres_exporter/postgres_exporter.go @@ -278,6 +278,19 @@ var builtinMetricMaps = map[string]intermediateMetricMap{ }, 0, }, + "pg_stat_archiver": { + map[string]ColumnMapping{ + "archived_count": {COUNTER, "Number of WAL files that have been successfully archived", nil, nil}, + "last_archived_wal": {DISCARD, "Name of the last WAL file successfully archived", nil, nil}, + "last_archived_time": {DISCARD, "Time of the last successful archive operation", nil, nil}, + "failed_count": {COUNTER, "Number of failed attempts for archiving WAL files", nil, nil}, + "last_failed_wal": {DISCARD, "Name of the WAL file of the last failed archival operation", nil, nil}, + "last_failed_time": {DISCARD, "Time of the last failed archival operation", nil, nil}, + "stats_reset": {DISCARD, "Time at which these statistics were last reset", nil, nil}, + "last_archive_age": {GAUGE, "Time in seconds since last WAL segment was successfully archived", nil, nil}, + }, + 0, + }, "pg_stat_activity": { map[string]ColumnMapping{ "datname": {LABEL, "Name of this database", nil, nil}, @@ -355,6 +368,17 @@ var queryOverrides = map[string][]OverrideQuery{ }, }, + "pg_stat_archiver": { + { + semver.MustParseRange(">=0.0.0"), + ` + SELECT *, + extract(epoch from now() - last_archived_time) AS last_archive_age + FROM pg_stat_archiver + `, + }, + }, + "pg_stat_activity": { // This query only works {