Skip to content

Commit e580e33

Browse files
authored
Merge branch 'master' into concurrency-improvements
2 parents de68444 + c768e64 commit e580e33

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ To scrape metrics from all databases on a database server, the database DSN's ca
166166
`--auto-discover-databases` flag. When true, `SELECT datname FROM pg_database` is run for all configured DSN's. From the
167167
result a new set of DSN's is created for which the metrics are scraped.
168168

169+
In addition, the option `--exclude-databases` adds the possibily to filter the result from the auto discovery to discard databases you do not need.
170+
169171
### Running as non-superuser
170172

171173
To be able to collect metrics from `pg_stat_activity` and `pg_stat_replication`

cmd/postgres_exporter/postgres_exporter.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
4040
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
4141
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
42+
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
4243
)
4344

4445
// Metric name parts.
@@ -896,6 +897,7 @@ type Exporter struct {
896897

897898
disableDefaultMetrics, disableSettingsMetrics, autoDiscoverDatabases bool
898899

900+
excludeDatabases []string
899901
dsn []string
900902
userQueriesPath string
901903
constantLabels prometheus.Labels
@@ -934,6 +936,13 @@ func AutoDiscoverDatabases(b bool) ExporterOpt {
934936
}
935937
}
936938

939+
// ExcludeDatabases allows to filter out result from AutoDiscoverDatabases
940+
func ExcludeDatabases(s string) ExporterOpt {
941+
return func(e *Exporter) {
942+
e.excludeDatabases = strings.Split(s, ",")
943+
}
944+
}
945+
937946
// WithUserQueriesPath configures user's queries path.
938947
func WithUserQueriesPath(p string) ExporterOpt {
939948
return func(e *Exporter) {
@@ -1352,6 +1361,9 @@ func (e *Exporter) discoverDatabaseDSNs() []string {
13521361
continue
13531362
}
13541363
for _, databaseName := range databaseNames {
1364+
if contains(e.excludeDatabases, databaseName) {
1365+
continue
1366+
}
13551367
parsedDSN.Path = databaseName
13561368
dsns[parsedDSN.String()] = struct{}{}
13571369
}
@@ -1420,6 +1432,15 @@ func getDataSources() []string {
14201432
return strings.Split(dsn, ",")
14211433
}
14221434

1435+
func contains(a []string, x string) bool {
1436+
for _, n := range a {
1437+
if x == n {
1438+
return true
1439+
}
1440+
}
1441+
return false
1442+
}
1443+
14231444
func main() {
14241445
kingpin.Version(fmt.Sprintf("postgres_exporter %s (built with %s)\n", Version, runtime.Version()))
14251446
log.AddFlags(kingpin.CommandLine)
@@ -1452,6 +1473,7 @@ func main() {
14521473
AutoDiscoverDatabases(*autoDiscoverDatabases),
14531474
WithUserQueriesPath(*queriesPath),
14541475
WithConstantLabels(*constantLabelsList),
1476+
ExcludeDatabases(*excludeDatabases),
14551477
)
14561478
defer func() {
14571479
exporter.servers.Close()

tools/src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/home/will/src/go/src/github.com/wrouesnel/postgres_exporter/tools/vendor
1+
/Users/alex/go/src/github.com/AlexisSellier/postgres_exporter/tools/vendor

0 commit comments

Comments
 (0)