1
- // Copyright 2022 The Prometheus Authors
1
+ // Copyright 2023 The Prometheus Authors
2
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
3
// you may not use this file except in compliance with the License.
4
4
// You may obtain a copy of the License at
@@ -34,9 +34,14 @@ func NewPGReplicationSlotCollector(logger log.Logger) (Collector, error) {
34
34
}
35
35
36
36
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" ,
40
45
[]string {"slot_name" }, nil ,
41
46
),
42
47
}
@@ -45,7 +50,8 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
45
50
rows , err := db .QueryContext (ctx ,
46
51
`SELECT
47
52
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
49
55
FROM
50
56
pg_replication_slots;` )
51
57
if err != nil {
@@ -55,14 +61,19 @@ func (PGReplicationSlotCollector) Update(ctx context.Context, db *sql.DB, ch cha
55
61
56
62
for rows .Next () {
57
63
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 {
60
67
return err
61
68
}
62
69
63
70
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 ,
66
77
)
67
78
}
68
79
if err := rows .Err (); err != nil {
0 commit comments