Skip to content

Commit

Permalink
PgBouncer: fixes and v1.20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevan committed Jul 21, 2023
1 parent 0c4a4d3 commit b4b70f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion collector/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ func (c *collector) collectFirst(db *sql.DB, o CollectConfig) {
// fill out some metadata fields
c.result.Metadata.At = time.Now().Unix()
c.result.Metadata.Version = pgmetrics.ModelSchemaVersion
c.getCurrentUser()

// collect either postgres, pgbouncer or pgpool metrics
if o.Pgpool {
// pgpool mode:
c.result.Metadata.Mode = "pgpool"
c.getCurrentUser()
c.collectPgpool()
} else if len(c.dbnames) == 1 && c.dbnames[0] == "pgbouncer" {
// pgbouncer mode:
Expand All @@ -367,6 +367,7 @@ func (c *collector) collectFirst(db *sql.DB, o CollectConfig) {
} else {
// postgres mode:
c.result.Metadata.Mode = "postgres"
c.getCurrentUser()
c.collectPostgres(o)
}
}
Expand Down Expand Up @@ -2674,6 +2675,7 @@ func (c *collector) collectPgBouncer() {
* sv_being_canceled, sv_idle, sv_used, sv_tested, sv_login, maxwait,
* maxwait_us, pool_mode
* 1.19: same as 1.18
* 1.20: same as 1.19
*/

func (c *collector) getPBPools() {
Expand Down Expand Up @@ -2736,6 +2738,7 @@ func (c *collector) getPBPools() {
* connect_time, request_time, wait, wait_us, close_needed, ptr,
* link, remote_pid, tls, application_name
* 1.19: same as 1.18
* 1.20: same as 1.19
*/

func (c *collector) getPBServers() {
Expand Down Expand Up @@ -2804,6 +2807,7 @@ func (c *collector) getPBServers() {
* connect_time, request_time, wait, wait_us, close_needed, ptr,
* link, remote_pid, tls, application_name
* 1.19: same as 1.18
* 1.20: same as 1.19
*/

func (c *collector) getPBClients() {
Expand Down Expand Up @@ -2878,6 +2882,7 @@ func (c *collector) getPBClients() {
* 1.17: same as 1.16
* 1.18: same as 1.17
* 1.19: same as 1.18
* 1.20: same as 1.19
*/

func (c *collector) getPBStats() {
Expand Down Expand Up @@ -2924,6 +2929,7 @@ func (c *collector) getPBStats() {
* 1.17: same as 1.16
* 1.18: same as 1.17
* 1.19: same as 1.18
* 1.20: same as 1.19
*/

func (c *collector) getPBDatabases() {
Expand Down
8 changes: 4 additions & 4 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,10 @@ type PgBouncerPool struct {
ClCancelReq int `json:"cl_cancel_req,omitempty"` // only in pgbouncer v1.16 & v1.17

// following fields present only in schema 1.14 and later
ClActiveCancelReq int `json:cl_active_cancel_req",omitempty"` // only in pgbouncer >= v1.18
ClWaitingCancelReq int `json:cl_waiting_cancel_req",omitempty"` // only in pgbouncer >= v1.18
SvActiveCancel int `json:sv_active_cancel",omitempty"` // only in pgbouncer >= v1.18
SvBeingCanceled int `json:sv_being_canceled",omitempty"` // only in pgbouncer >= v1.18
ClActiveCancelReq int `json:"cl_active_cancel_req,omitempty"` // only in pgbouncer >= v1.18
ClWaitingCancelReq int `json:"cl_waiting_cancel_req,omitempty"` // only in pgbouncer >= v1.18
SvActiveCancel int `json:"sv_active_cancel,omitempty"` // only in pgbouncer >= v1.18
SvBeingCanceled int `json:"sv_being_canceled,omitempty"` // only in pgbouncer >= v1.18
}

// PgBouncerDatabase contains information about one database of PgBouncer
Expand Down

0 comments on commit b4b70f2

Please sign in to comment.