File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ package collector
16
16
import (
17
17
"context"
18
18
"database/sql"
19
+ "log/slog"
19
20
21
+ "github.com/blang/semver/v4"
20
22
"github.com/prometheus/client_golang/prometheus"
21
23
)
22
24
@@ -29,10 +31,11 @@ func init() {
29
31
}
30
32
31
33
type PGStatCheckpointerCollector struct {
34
+ log * slog.Logger
32
35
}
33
36
34
- func NewPGStatCheckpointerCollector (collectorConfig ) (Collector , error ) {
35
- return & PGStatCheckpointerCollector {}, nil
37
+ func NewPGStatCheckpointerCollector (config collectorConfig ) (Collector , error ) {
38
+ return & PGStatCheckpointerCollector {log : config . logger }, nil
36
39
}
37
40
38
41
var (
@@ -104,8 +107,15 @@ var (
104
107
FROM pg_stat_checkpointer;`
105
108
)
106
109
107
- func (PGStatCheckpointerCollector ) Update (ctx context.Context , instance * instance , ch chan <- prometheus.Metric ) error {
110
+ func (c PGStatCheckpointerCollector ) Update (ctx context.Context , instance * instance , ch chan <- prometheus.Metric ) error {
108
111
db := instance .getDB ()
112
+
113
+ before17 := instance .version .Compare (semver .MustParse ("17.0.0" ))
114
+ if before17 < 0 {
115
+ c .log .Warn ("pg_stat_checkpointer collector is not available on PostgreSQL < 17.0.0, skipping" )
116
+ return nil
117
+ }
118
+
109
119
row := db .QueryRowContext (ctx , statCheckpointerQuery )
110
120
111
121
// num_timed = nt = bigint
You can’t perform that action at this time.
0 commit comments