From c55a3b3c5b95dad4513e96a1218d9ec2e3916ef8 Mon Sep 17 00:00:00 2001 From: Ajay Bhat Date: Thu, 24 Dec 2020 21:06:18 +0530 Subject: [PATCH] Fixes (#364) (#387) Have a custom prefix for each of the default metrics created by postgres_exporter Co-authored-by: Will Rouesnel --- README.md | 3 +++ cmd/postgres_exporter/postgres_exporter.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index ff5174b3..72879ac4 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,9 @@ The following environment variables configure the exporter: * `PG_EXPORTER_EXCLUDE_DATABASES` A comma-separated list of databases to remove when autoDiscoverDatabases is enabled. Default is empty string. +* `PG_EXPORTER_METRIC_PREFIX` + A prefix to use for each of the default metrics exported by postgres-exporter. Default is `pg` + Settings set by environment variables starting with `PG_` will be overwritten by the corresponding CLI flag if given. ### Setting the Postgres server's data source name diff --git a/cmd/postgres_exporter/postgres_exporter.go b/cmd/postgres_exporter/postgres_exporter.go index 9151ba3d..1fe0d833 100644 --- a/cmd/postgres_exporter/postgres_exporter.go +++ b/cmd/postgres_exporter/postgres_exporter.go @@ -53,6 +53,7 @@ var ( onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool() constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String() excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String() + metricPrefix = kingpin.Flag("metric-prefix", "A metric prefix can be used to have non-default (not \"pg\") prefixes for each of the metrics").Default("pg").Envar("PG_EXPORTER_METRIC_PREFIX").String() ) // Metric name parts. @@ -626,6 +627,8 @@ func makeDescMap(pgVersion semver.Version, serverLabels prometheus.Labels, metri } } + namespace := strings.Replace(namespace, "pg", *metricPrefix, 1) + // Determine how to convert the column based on its usage. // nolint: dupl switch columnMapping.usage {