|
55 | 55 | onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool() |
56 | 56 | constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String() |
57 | 57 | excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String() |
| 58 | + includeDatabases = kingpin.Flag("include-databases", "A list of databases to include when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_INCLUDE_DATABASES").String() |
58 | 59 | 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() |
59 | 60 | logger = log.NewNopLogger() |
60 | 61 | ) |
@@ -1099,6 +1100,7 @@ type Exporter struct { |
1099 | 1100 | disableDefaultMetrics, disableSettingsMetrics, autoDiscoverDatabases bool |
1100 | 1101 |
|
1101 | 1102 | excludeDatabases []string |
| 1103 | + includeDatabases []string |
1102 | 1104 | dsn []string |
1103 | 1105 | userQueriesPath string |
1104 | 1106 | constantLabels prometheus.Labels |
@@ -1144,6 +1146,13 @@ func ExcludeDatabases(s string) ExporterOpt { |
1144 | 1146 | } |
1145 | 1147 | } |
1146 | 1148 |
|
| 1149 | +// IncludeDatabases allows to filter result from AutoDiscoverDatabases |
| 1150 | +func IncludeDatabases(s string) ExporterOpt { |
| 1151 | + return func(e *Exporter) { |
| 1152 | + e.includeDatabases = strings.Split(s, ",") |
| 1153 | + } |
| 1154 | +} |
| 1155 | + |
1147 | 1156 | // WithUserQueriesPath configures user's queries path. |
1148 | 1157 | func WithUserQueriesPath(p string) ExporterOpt { |
1149 | 1158 | return func(e *Exporter) { |
@@ -1678,6 +1687,10 @@ func (e *Exporter) discoverDatabaseDSNs() []string { |
1678 | 1687 | continue |
1679 | 1688 | } |
1680 | 1689 |
|
| 1690 | + if len(e.includeDatabases) != 0 && !contains(e.includeDatabases, databaseName) { |
| 1691 | + continue |
| 1692 | + } |
| 1693 | + |
1681 | 1694 | if dsnURI != nil { |
1682 | 1695 | dsnURI.Path = databaseName |
1683 | 1696 | dsn = dsnURI.String() |
@@ -1822,6 +1835,7 @@ func main() { |
1822 | 1835 | WithUserQueriesPath(*queriesPath), |
1823 | 1836 | WithConstantLabels(*constantLabelsList), |
1824 | 1837 | ExcludeDatabases(*excludeDatabases), |
| 1838 | + IncludeDatabases(*includeDatabases), |
1825 | 1839 | } |
1826 | 1840 |
|
1827 | 1841 | exporter := NewExporter(dsn, opts...) |
|
0 commit comments