Skip to content

Commit

Permalink
pgpool: support replication_delay of show pool_nodes in seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevan committed Aug 22, 2023
1 parent 3614cea commit 6fda1db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions collector/pgpool.go
Expand Up @@ -97,20 +97,20 @@ func (c *collector) getPPNodes() {

for rows.Next() {
var b pgmetrics.PgpoolBackend
var lastStatusChange string
var lastStatusChange, replicationDelay string
if ncols == 10 {
err = rows.Scan(&b.NodeID, &b.Hostname, &b.Port, &b.Status,
&b.LBWeight, &b.Role, &b.SelectCount, &b.LoadBalanceNode,
&b.ReplicationDelay, &lastStatusChange)
&replicationDelay, &lastStatusChange)
} else if ncols == 12 {
err = rows.Scan(&b.NodeID, &b.Hostname, &b.Port, &b.Status,
&b.LBWeight, &b.Role, &b.SelectCount, &b.LoadBalanceNode,
&b.ReplicationDelay, &b.ReplicationState, &b.ReplicationSyncState,
&replicationDelay, &b.ReplicationState, &b.ReplicationSyncState,
&lastStatusChange)
} else if ncols == 14 {
err = rows.Scan(&b.NodeID, &b.Hostname, &b.Port, &b.Status,
&b.PgStatus, &b.LBWeight, &b.Role, &b.PgRole, &b.SelectCount,
&b.LoadBalanceNode, &b.ReplicationDelay, &b.ReplicationState,
&b.LoadBalanceNode, &replicationDelay, &b.ReplicationState,
&b.ReplicationSyncState, &lastStatusChange)
} else {
log.Fatalf("pgpool: unsupported number of columns %d in 'SHOW POOL_NODES'", ncols)
Expand All @@ -119,6 +119,13 @@ func (c *collector) getPPNodes() {
log.Fatalf("pgpool: show pool_nodes query scan failed: %v", err)
}
b.LastStatusChange = pgpoolScanTime(lastStatusChange)
if strings.Contains(replicationDelay, "second") {
if parts := strings.Fields(replicationDelay); len(parts) == 2 {
b.ReplicationDelaySeconds, _ = strconv.ParseFloat(parts[0], 64)
}
} else {
b.ReplicationDelay, _ = strconv.ParseInt(replicationDelay, 10, 64)
}
c.result.Pgpool.Backends = append(c.result.Pgpool.Backends, b)
}
if err := rows.Err(); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion model.go
Expand Up @@ -19,6 +19,7 @@ package pgmetrics
// ModelSchemaVersion is the schema version of the "Model" data structure
// defined below. It is in the "semver" notation. Version history:
//
// 1.15 - Pgpool ReplicationDelaySeconds
// 1.14 - PgBouncer 1.19, Pgpool support
// 1.13 - Citus 11 support, Postgres 15
// 1.12 - Azure metrics, queryid in plan, progress views
Expand Down Expand Up @@ -1001,7 +1002,7 @@ type PgpoolBackend struct {
FatalCount int64 `json:"fatal_cnt,omitempty"` // pgpool >= v4.2
ErrorCount int64 `json:"error_cnt,omitempty"` // pgpool >= v4.2
LoadBalanceNode bool `json:"load_balance_node"`
ReplicationDelay int64 `json:"replication_delay"`
ReplicationDelay int64 `json:"replication_delay,omitempty"`
ReplicationState string `json:"replication_state,omitempty"` // pgpool >= v4.1
ReplicationSyncState string `json:"replication_sync_state,omitempty"` // pgpool >= v4.1
LastStatusChange int64 `json:"last_status_change"`
Expand All @@ -1019,6 +1020,8 @@ type PgpoolBackend struct {
HCLastSuccessHealthCheck int64 `json:"last_successful_health_check,omitempty"` // pgpool >= v4.2
HCLastSkipHealthCheck int64 `json:"last_skip_health_check,omitempty"` // pgpool >= v4.2
HCLastFailedHealthCheck int64 `json:"last_failed_health_check,omitempty"` // pgpool >= v4.2
// following fields present only in schema 1.15 and later
ReplicationDelaySeconds float64 `json:"replication_delay_secs,omitempty"`
}

// PgpoolQueryCache contains in memory query cache statistics of Pgpool.
Expand Down

0 comments on commit 6fda1db

Please sign in to comment.