Skip to content

Commit 9b13780

Browse files
author
Zachary Caldarola
committed
addressing comments
Signed-off-by: Zachary Caldarola <[email protected]>
1 parent 3007500 commit 9b13780

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

collector/pg_replication_slots.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

3636
var 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
4550
rows, err := db.QueryContext(ctx,
4651
`SELECT
4752
slot_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
4955
FROM
5056
pg_replication_slots;`)
5157
if err != nil {
@@ -55,14 +61,19 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
5561

5662
for rows.Next() {
5763
var 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 {
6067
return err
6168
}
6269

6370
ch <- 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
}
6879
if err := rows.Err(); err != nil {

0 commit comments

Comments
 (0)