mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-09 10:47:18 +00:00
Discover only databases that are not templates and allow connections (#297)
* Discover only databases that are not templates and allow connections * Update readme
This commit is contained in:
parent
c768e64548
commit
1ab8d2bbc8
@ -163,7 +163,7 @@ flag. This removes all built-in metrics, and uses only metrics defined by querie
|
||||
|
||||
### Automatically discover databases
|
||||
To scrape metrics from all databases on a database server, the database DSN's can be dynamically discovered via the
|
||||
`--auto-discover-databases` flag. When true, `SELECT datname FROM pg_database` is run for all configured DSN's. From the
|
||||
`--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
|
||||
result a new set of DSN's is created for which the metrics are scraped.
|
||||
|
||||
In addition, the option `--exclude-databases` adds the possibily to filter the result from the auto discovery to discard databases you do not need.
|
||||
|
@ -1074,7 +1074,7 @@ func newDesc(subsystem, name, help string, labels prometheus.Labels) *prometheus
|
||||
}
|
||||
|
||||
func queryDatabases(server *Server) ([]string, error) {
|
||||
rows, err := server.db.Query("SELECT datname FROM pg_database") // nolint: safesql
|
||||
rows, err := server.db.Query("SELECT datname FROM pg_database WHERE datallowconn = true AND datistemplate = false") // nolint: safesql
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error retrieving databases: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user