1- // Copyright 2022 The Prometheus Authors
1+ // Copyright 2023 The Prometheus Authors
22// Licensed under the Apache License, Version 2.0 (the "License");
33// you may not use this file except in compliance with the License.
44// You may obtain a copy of the License at
@@ -34,9 +34,14 @@ func NewPGReplicationSlotCollector(logger log.Logger) (Collector, error) {
3434}
3535
3636var pgReplicationSlot = map [string ]* prometheus.Desc {
37- "lsn_distance" : prometheus .NewDesc (
38- "pg_replication_slot_lsn_distance" ,
39- "Disk space used by the database" ,
37+ "current_wal_lsn" : prometheus .NewDesc (
38+ "pg_replication_slot_current_wal_lsn" ,
39+ "current wal lsn value" ,
40+ []string {"slot_name" }, nil ,
41+ ),
42+ "confirmed_flush_lsn" : prometheus .NewDesc (
43+ "pg_replication_slot_confirmed_flush_lsn" ,
44+ "last lsn confirmed flushed to the replication slot" ,
4045[]string {"slot_name" }, nil ,
4146),
4247}
@@ -45,7 +50,8 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
4550rows , err := db .QueryContext (ctx ,
4651`SELECT
4752slot_name,
48- (pg_current_wal_lsn() - confirmed_flush_lsn) AS lsn_distance
53+ pg_current_wal_lsn() AS current_wal_lsn,
54+ confirmed_flush_lsn
4955FROM
5056pg_replication_slots;` )
5157if err != nil {
@@ -55,14 +61,19 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
5561
5662for rows .Next () {
5763var slot_name string
58- var size int64
59- if err := rows .Scan (& slot_name , & size ); err != nil {
64+ var wal_lsn int64
65+ var flush_lsn int64
66+ if err := rows .Scan (& slot_name , & wal_lsn , & flush_lsn ); err != nil {
6067return err
6168}
6269
6370ch <- prometheus .MustNewConstMetric (
64- pgReplicationSlot ["size_bytes" ],
65- prometheus .GaugeValue , float64 (size ), slot_name ,
71+ pgReplicationSlot ["current_wal_lsn" ],
72+ prometheus .GaugeValue , float64 (wal_lsn ), slot_name ,
73+ )
74+ ch <- prometheus .MustNewConstMetric (
75+ pgReplicationSlot ["confirmed_flush_lsn" ],
76+ prometheus .GaugeValue , float64 (flush_lsn ), slot_name ,
6677)
6778}
6879if err := rows .Err (); err != nil {
0 commit comments