Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Add pgbouncer_up metric.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Jun 4, 2021
1 parent 188eb81 commit c3de7b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions internal/collector/pgbouncer_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const pgbouncerStatsQuery = "SHOW STATS"

type pgbouncerStatsCollector struct {
up typedDesc
xacts typedDesc
queries typedDesc
bytes typedDesc
Expand All @@ -25,6 +26,12 @@ func NewPgbouncerStatsCollector(constLabels labels, settings model.CollectorSett

return &pgbouncerStatsCollector{
labelNames: pgbouncerLabelNames,
up: newBuiltinTypedDesc(
descOpts{"pgbouncer", "", "up", "State of Pgbouncer service: 0 is down, 1 is up.", 0},
prometheus.CounterValue,
nil, constLabels,
settings.Filters,
),
xacts: newBuiltinTypedDesc(
descOpts{"pgbouncer", "", "transactions_total", "Total number of SQL transactions processed, for each database.", 0},
prometheus.CounterValue,
Expand Down Expand Up @@ -60,6 +67,7 @@ func NewPgbouncerStatsCollector(constLabels labels, settings model.CollectorSett
func (c *pgbouncerStatsCollector) Update(config Config, ch chan<- prometheus.Metric) error {
conn, err := store.New(config.ConnString)
if err != nil {
ch <- c.up.newConstMetric(0)
return err
}
defer conn.Close()
Expand All @@ -81,6 +89,9 @@ func (c *pgbouncerStatsCollector) Update(config Config, ch chan<- prometheus.Met
ch <- c.time.newConstMetric(stat.waittime, stat.database, "waiting", "none")
}

// All is ok, collect up metric.
ch <- c.up.newConstMetric(1)

return nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/collector/pgbouncer_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func TestPgbouncerStatsCollector_Update(t *testing.T) {
var input = pipelineInput{
required: []string{
"pgbouncer_up",
"pgbouncer_transactions_total",
"pgbouncer_queries_total",
"pgbouncer_bytes_total",
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/postgres_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type postgresActivityCollector struct {
func NewPostgresActivityCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) {
return &postgresActivityCollector{
up: newBuiltinTypedDesc(
descOpts{"postgres", "", "up", "State of Postgres service: 0 is down, 1 is up.", 0},
descOpts{"postgres", "", "up", "State of PostgreSQL service: 0 is down, 1 is up.", 0},
prometheus.GaugeValue,
nil, constLabels,
settings.Filters,
Expand Down

0 comments on commit c3de7b9

Please sign in to comment.