You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -163,9 +163,11 @@ flag. This removes all built-in metrics, and uses only metrics defined by querie
163
163
164
164
### Automatically discover databases
165
165
To scrape metrics from all databases on a database server, the database DSN's can be dynamically discovered via the
166
-
`--auto-discover-databases` flag. When true, `SELECT datname FROM pg_database` is run for all configured DSN's. From the
166
+
`--auto-discover-databases` flag. When true, `SELECT datname FROM pg_database WHERE datallowconn = true AND datistemplate = false` is run for all configured DSN's. From the
167
167
result a new set of DSN's is created for which the metrics are scraped.
168
168
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
+
169
171
### Running as non-superuser
170
172
171
173
To be able to collect metrics from `pg_stat_activity` and `pg_stat_replication`
@@ -206,6 +208,7 @@ ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
206
208
-- GRANT postgres_exporter TO <MASTER_USER>;
207
209
CREATESCHEMAIF NOT EXISTS postgres_exporter;
208
210
GRANT USAGE ON SCHEMA postgres_exporter TO postgres_exporter;
211
+
GRANT CONNECT ON DATABASE postgres TO postgres_exporter;
209
212
210
213
CREATE OR REPLACEFUNCTIONget_pg_stat_activity() RETURNS SETOF pg_stat_activity AS
Copy file name to clipboardExpand all lines: cmd/postgres_exporter/postgres_exporter.go
+96-29Lines changed: 96 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,7 @@ var (
39
39
queriesPath=kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
40
40
onlyDumpMaps=kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
41
41
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()
42
43
)
43
44
44
45
// Metric name parts.
@@ -128,6 +129,16 @@ type MetricMap struct {
128
129
conversionfunc(interface{}) (float64, bool) // Conversion function to turn PG result into float64
129
130
}
130
131
132
+
// ErrorConnectToServer is a connection to PgSQL server error
133
+
typeErrorConnectToServerstruct {
134
+
Msgstring
135
+
}
136
+
137
+
// Error returns error
138
+
func (e*ErrorConnectToServer) Error() string {
139
+
returne.Msg
140
+
}
141
+
131
142
// TODO: revisit this with the semver system
132
143
funcdumpMaps() {
133
144
// TODO: make this function part of the exporter
@@ -231,6 +242,7 @@ var builtinMetricMaps = map[string]map[string]ColumnMapping{
231
242
"restart_lsn": {DISCARD, "The address (LSN) of oldest WAL which still might be required by the consumer of this slot and thus won't be automatically removed during checkpoints", nil, nil},
0 commit comments