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

Commit

Permalink
Revert "Add support for user-defined metrics to postgres/databases co…
Browse files Browse the repository at this point in the history
…llector."

This reverts commit 54b920f
  • Loading branch information
lesovsky committed May 15, 2021
1 parent 05ef56f commit 03cfff3
Showing 1 changed file with 4 additions and 42 deletions.
46 changes: 4 additions & 42 deletions internal/collector/postgres_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,19 @@ type postgresDatabasesCollector struct {
statsage typedDesc
xidlimit typedDesc
labelNames []string
custom []typedDescSet
}

// NewPostgresDatabasesCollector returns a new Collector exposing postgres databases stats.
// For details see https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-DATABASE-VIEW
func NewPostgresDatabasesCollector(constLabels prometheus.Labels, settings model.CollectorSettings) (Collector, error) {
// This instance of builtinSubsystems just used for detecting collisions with user-defined metrics.
// This must be always synchronized with metric descriptors in returned value.
builtinSubsystems := model.Subsystems{
"database": {
Metrics: model.Metrics{
{ShortName: "datname"},
{ShortName: "xact_commits_total"},
{ShortName: "xact_rollbacks_total"},
{ShortName: "conflicts_total"},
{ShortName: "deadlocks_total"},
{ShortName: "blocks_total"},
{ShortName: "tuples_total"},
{ShortName: "temp_bytes_total"},
{ShortName: "temp_files_total"},
{ShortName: "blk_time_seconds"},
{ShortName: "size_bytes"},
{ShortName: "stats_age_seconds"},
},
},
"xacts": {
Metrics: model.Metrics{
{ShortName: "xid"},
{ShortName: "left_before_wraparound"},
},
},
}

removeCollisions(builtinSubsystems, settings.Subsystems)

databaseLabelNames := []string{"datname"}
var databaseLabelNames = []string{"datname"}

return &postgresDatabasesCollector{
labelNames: databaseLabelNames,
commits: typedDesc{
desc: prometheus.NewDesc(
prometheus.BuildFQName("postgres", "database", "xact_commits_total"),
"Total number of transactions had been committed.",
"Total number of transactions had been commited.",
databaseLabelNames, constLabels,
), valueType: prometheus.CounterValue,
},
Expand Down Expand Up @@ -154,11 +124,10 @@ func NewPostgresDatabasesCollector(constLabels prometheus.Labels, settings model
xidlimit: typedDesc{
desc: prometheus.NewDesc(
prometheus.BuildFQName("postgres", "xacts", "left_before_wraparound"),
"The least number of transactions (among all databases) left before force shutdown due to XID wraparound.",
"The number of transactions left before force shutdown due to XID wraparound.",
[]string{"xid"}, constLabels,
), valueType: prometheus.CounterValue,
},
custom: newDeskSetsFromSubsystems("postgres", settings.Subsystems, constLabels),
}, nil
}

Expand All @@ -168,6 +137,7 @@ func (c *postgresDatabasesCollector) Update(config Config, ch chan<- prometheus.
if err != nil {
return err
}
defer conn.Close()

res, err := conn.Query(databaseQuery)
if err != nil {
Expand All @@ -181,8 +151,6 @@ func (c *postgresDatabasesCollector) Update(config Config, ch chan<- prometheus.
return err
}

conn.Close()

xidStats := parsePostgresXidLimitStats(res)

for _, stat := range stats {
Expand Down Expand Up @@ -210,12 +178,6 @@ func (c *postgresDatabasesCollector) Update(config Config, ch chan<- prometheus.
ch <- c.xidlimit.mustNewConstMetric(xidStats.prepared, "pg_prepared_xacts")
ch <- c.xidlimit.mustNewConstMetric(xidStats.replSlot, "pg_replication_slots")

// Update user-defined metrics.
err = updateAllDescSets(config, c.custom, ch)
if err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 03cfff3

Please sign in to comment.