Skip to content

Commit

Permalink
replication: handle null from pg_wal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
apetruhin committed Aug 10, 2022
1 parent 0115d8d commit 1579703
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
if c.replicationStatus != nil {
rs := c.replicationStatus
if rs.isInRecovery {
ch <- counter(dWalReceiveLsn, float64(rs.receiveLsn))
ch <- counter(dWalReplyLsn, float64(rs.replyLsn))
if rs.receiveLsn.Valid {
ch <- counter(dWalReceiveLsn, float64(rs.receiveLsn.Int64))
}
if rs.replyLsn.Valid {
ch <- counter(dWalReplyLsn, float64(rs.replyLsn.Int64))
}
isReplayPaused := 0.0
if rs.isReplayPaused {
isReplayPaused = 1.0
Expand All @@ -300,7 +304,9 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
}
ch <- gauge(dWalReceiverStatus, float64(rs.walReceiverStatus), host, port)
} else {
ch <- counter(dWalCurrentLsn, float64(rs.currentLsn))
if rs.currentLsn.Valid {
ch <- counter(dWalCurrentLsn, float64(rs.currentLsn.Int64))
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions collector/pg_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func findValue(src string, re *regexp.Regexp) string {
type replicationStatus struct {
isInRecovery bool

currentLsn int64
receiveLsn int64
replyLsn int64
currentLsn sql.NullInt64
receiveLsn sql.NullInt64
replyLsn sql.NullInt64

isReplayPaused bool

Expand Down

0 comments on commit 1579703

Please sign in to comment.