Skip to content

Commit c55a3b3

Browse files
ajaybhatwrouesnel
andauthored
Have a custom prefix for each of the default metrics created by postgres_exporter Co-authored-by: Will Rouesnel <[email protected]>
1 parent 3fd1c2c commit c55a3b3

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ The following environment variables configure the exporter:
140140
* `PG_EXPORTER_EXCLUDE_DATABASES`
141141
A comma-separated list of databases to remove when autoDiscoverDatabases is enabled. Default is empty string.
142142

143+
* `PG_EXPORTER_METRIC_PREFIX`
144+
A prefix to use for each of the default metrics exported by postgres-exporter. Default is `pg`
145+
143146
Settings set by environment variables starting with `PG_` will be overwritten by the corresponding CLI flag if given.
144147

145148
### Setting the Postgres server's data source name

cmd/postgres_exporter/postgres_exporter.go

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
5454
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
5555
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
56+
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()
5657
)
5758

5859
// Metric name parts.
@@ -626,6 +627,8 @@ func makeDescMap(pgVersion semver.Version, serverLabels prometheus.Labels, metri
626627
}
627628
}
628629

630+
namespace := strings.Replace(namespace, "pg", *metricPrefix, 1)
631+
629632
// Determine how to convert the column based on its usage.
630633
// nolint: dupl
631634
switch columnMapping.usage {

0 commit comments

Comments
 (0)