1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-07-31 20:44:25 +03:00

Refactor collector descriptors

Use individual collector metric descriptor vars to help avoid
miss-mapped or unused metrics.

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
SuperQ
2023-06-01 10:04:35 +02:00
parent dde6e6e52a
commit 425c4938ef
3 changed files with 52 additions and 54 deletions

View File

@ -41,13 +41,11 @@ func NewPGDatabaseCollector(config collectorConfig) (Collector, error) {
}, nil
}
var pgDatabase = map[string]*prometheus.Desc{
"size_bytes": prometheus.NewDesc(
"pg_database_size_bytes",
"Disk space used by the database",
[]string{"datname"}, nil,
),
}
var pgDatabaseSizeDesc = prometheus.NewDesc(
"pg_database_size_bytes",
"Disk space used by the database",
[]string{"datname"}, nil,
)
// Update implements Collector and exposes database size.
// It is called by the Prometheus registry when collecting metrics.
@ -96,7 +94,7 @@ func (c PGDatabaseCollector) Update(ctx context.Context, db *sql.DB, ch chan<- p
}
ch <- prometheus.MustNewConstMetric(
pgDatabase["size_bytes"],
pgDatabaseSizeDesc,
prometheus.GaugeValue, float64(size), datname,
)
}