diff --git a/cmd/postgres_exporter/postgres_exporter.go b/cmd/postgres_exporter/postgres_exporter.go index 37795aac..a115876b 100644 --- a/cmd/postgres_exporter/postgres_exporter.go +++ b/cmd/postgres_exporter/postgres_exporter.go @@ -315,6 +315,16 @@ var builtinMetricMaps = map[string]intermediateMetricMap{ true, 0, }, + "pg_replication_slots": { + map[string]ColumnMapping{ + "slot_name": {LABEL, "Name of the replication slot", nil, nil}, + "database": {LABEL, "Name of the database", nil, nil}, + "active": {GAUGE, "Flag indicating if the slot is active", nil, nil}, + "pg_wal_lsn_diff": {GAUGE, "Replication lag in bytes", nil, nil}, + }, + true, + 0, + }, "pg_stat_archiver": { map[string]ColumnMapping{ "archived_count": {COUNTER, "Number of WAL files that have been successfully archived", nil, nil}, @@ -407,6 +417,16 @@ var queryOverrides = map[string][]OverrideQuery{ }, }, + "pg_replication_slots": { + { + semver.MustParseRange(">=9.4.0"), + ` + SELECT slot_name, database, active, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) + FROM pg_replication_slots + `, + }, + }, + "pg_stat_archiver": { { semver.MustParseRange(">=0.0.0"),