@@ -44,16 +44,22 @@ var pgReplicationSlot = map[string]*prometheus.Desc{
4444"last lsn confirmed flushed to the replication slot" ,
4545[]string {"slot_name" }, nil ,
4646),
47+ "is_active" : prometheus .NewDesc (
48+ "pg_replication_slot_is_active" ,
49+ "last lsn confirmed flushed to the replication slot" ,
50+ []string {"slot_name" }, nil ,
51+ ),
4752}
4853
4954func (PGReplicationSlotCollector ) Update (ctx context.Context , db * sql.DB , ch chan <- prometheus.Metric ) error {
5055rows , err := db .QueryContext (ctx ,
5156`SELECT
5257slot_name,
53- pg_current_wal_lsn() AS current_wal_lsn,
54- confirmed_flush_lsn
55- FROM
56- pg_replication_slots;` )
58+ pg_current_wal_lsn() - '0/0' AS current_wal_lsn,
59+ coalesce(confirmed_flush_lsn, '0/0') - '0/0',
60+ active
61+ FROM
62+ pg_replication_slots;` )
5763if err != nil {
5864return err
5965}
@@ -63,17 +69,24 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
6369var slot_name string
6470var wal_lsn int64
6571var flush_lsn int64
66- if err := rows .Scan (& slot_name , & wal_lsn , & flush_lsn ); err != nil {
72+ var is_active int
73+ if err := rows .Scan (& slot_name , & wal_lsn , & flush_lsn , & is_active ); err != nil {
6774return err
6875}
6976
7077ch <- prometheus .MustNewConstMetric (
7178pgReplicationSlot ["current_wal_lsn" ],
7279prometheus .GaugeValue , float64 (wal_lsn ), slot_name ,
7380)
81+ if (is_active == 1 ) {
82+ ch <- prometheus .MustNewConstMetric (
83+ pgReplicationSlot ["confirmed_flush_lsn" ],
84+ prometheus .GaugeValue , float64 (flush_lsn ), slot_name ,
85+ )
86+ }
7487ch <- prometheus .MustNewConstMetric (
75- pgReplicationSlot ["confirmed_flush_lsn " ],
76- prometheus .GaugeValue , float64 (flush_lsn ), slot_name ,
88+ pgReplicationSlot ["is_active " ],
89+ prometheus .GaugeValue , int (flush_lsn ), slot_name ,
7790)
7891}
7992if err := rows .Err (); err != nil {
0 commit comments