Skip to content

Commit

Permalink
Pgpool 4.x support, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevan committed May 11, 2023
1 parent 669e548 commit 114f7a0
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 25 deletions.
2 changes: 2 additions & 0 deletions cmd/pgmetrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Collection options:
--log-span=MINS examine the last MINS minutes of logs (default: 5)
--aws-rds-dbid AWS RDS/Aurora database instance identifier
--az-resource Azure resource ID
--pgpool collect only Pgpool metrics
Output options:
-f, --format=FORMAT output format; "human", "json" or "csv" (default: "human")
Expand Down Expand Up @@ -221,6 +222,7 @@ func (o *options) parse() (args []string) {
s.UintVarLong(&o.CollectConfig.LogSpan, "log-span", 0, "")
s.StringVarLong(&o.CollectConfig.RDSDBIdentifier, "aws-rds-dbid", 0, "")
s.StringVarLong(&o.CollectConfig.AzureResourceID, "az-resource", 0, "")
s.BoolVarLong(&o.CollectConfig.Pgpool, "pgpool", 0, "").SetFlag()
// output
s.StringVarLong(&o.format, "format", 'f', "")
s.StringVarLong(&o.output, "output", 'o', "")
Expand Down
60 changes: 36 additions & 24 deletions collector/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type CollectConfig struct {
RDSDBIdentifier string
AllDBs bool
AzureResourceID string
Pgpool bool // collect only pgpool information

// connection
Host string
Expand Down Expand Up @@ -349,40 +350,51 @@ func (c *collector) collectFirst(db *sql.DB, o CollectConfig) {
c.stmtsLimit = o.StmtsLimit
c.logSpan = o.LogSpan

// current time is the report start time
// fill out some metadata fields
c.result.Metadata.At = time.Now().Unix()
c.result.Metadata.Version = pgmetrics.ModelSchemaVersion

if len(c.dbnames) == 1 && c.dbnames[0] == "pgbouncer" {
c.getCurrentUser()

// collect either postgres, pgbouncer or pgpool metrics
if o.Pgpool {
// pgpool mode:
c.result.Metadata.Mode = "pgpool"
c.collectPgpool()
} else if len(c.dbnames) == 1 && c.dbnames[0] == "pgbouncer" {
// pgbouncer mode:
c.result.Metadata.Mode = "pgbouncer"
c.collectPgBouncer()
} else {
// postgres mode:
// get settings and other configuration
c.getCurrentUser()
c.getSettings()
if v, err := strconv.Atoi(c.setting("server_version_num")); err != nil {
log.Fatalf("bad server_version_num: %v", err)
} else {
c.version = v
}
c.getLocal()
if c.local {
c.dataDir = c.setting("data_directory")
if len(c.dataDir) == 0 {
c.dataDir = os.Getenv("PGDATA")
}
c.result.Metadata.Mode = "postgres"
c.collectPostgres(o)
}
}

func (c *collector) collectPostgres(o CollectConfig) {
// get settings and other configuration
c.getSettings()
if v, err := strconv.Atoi(c.setting("server_version_num")); err != nil {
log.Fatalf("bad server_version_num: %v", err)
} else {
c.version = v
}
c.getLocal()
if c.local {
c.dataDir = c.setting("data_directory")
if len(c.dataDir) == 0 {
c.dataDir = os.Getenv("PGDATA")
}
}

c.collectCluster(o)
if c.local {
// Only implemented for Linux for now.
if runtime.GOOS == "linux" {
c.collectSystem(o)
}
c.collectCluster(o)
if c.local {
// Only implemented for Linux for now.
if runtime.GOOS == "linux" {
c.collectSystem(o)
}
c.collectDatabase(o)
}
c.collectDatabase(o)
}

func (c *collector) collectNext(db *sql.DB, o CollectConfig) {
Expand Down
Loading

0 comments on commit 114f7a0

Please sign in to comment.