Skip to content

Commit 97239bc

Browse files
committed
fix converting NULL to uint64 is unsupported in size table
1 parent 98f75c7 commit 97239bc

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

collector/pg_wal.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package collector
1515

1616
import (
1717
"context"
18-
18+
"database/sql"
1919
"github.com/prometheus/client_golang/prometheus"
2020
)
2121

@@ -66,19 +66,34 @@ func (c PGWALCollector) Update(ctx context.Context, instance *instance, ch chan<
6666
pgWALQuery,
6767
)
6868

69-
var segments uint64
70-
var size uint64
69+
var segments sql.NullInt64
70+
var size sql.NullInt64
7171
err := row.Scan(&segments, &size)
7272
if err != nil {
7373
return err
7474
}
75+
76+
var segmentsValue float64
77+
if segments.Valid {
78+
segmentsValue = float64(segments.Int64)
79+
} else {
80+
segmentsValue = 0
81+
}
82+
83+
var sizeValue float64
84+
if size.Valid {
85+
sizeValue = float64(size.Int64)
86+
} else {
87+
sizeValue = 0
88+
}
89+
7590
ch <- prometheus.MustNewConstMetric(
7691
pgWALSegments,
77-
prometheus.GaugeValue, float64(segments),
92+
prometheus.GaugeValue, segmentsValue,
7893
)
7994
ch <- prometheus.MustNewConstMetric(
8095
pgWALSize,
81-
prometheus.GaugeValue, float64(size),
96+
prometheus.GaugeValue, sizeValue,
8297
)
8398
return nil
8499
}

0 commit comments

Comments
 (0)