You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-11-07 17:46:22 +03:00
Merge pull request #521 from pvanderlinden/fix-auto-discovery
fix parsing include databases
This commit is contained in:
15
README.md
15
README.md
@@ -192,8 +192,8 @@ flag. This removes all built-in metrics, and uses only metrics defined by querie
|
|||||||
(so you must supply one, otherwise the exporter will return nothing but internal statuses and not your database).
|
(so you must supply one, otherwise the exporter will return nothing but internal statuses and not your database).
|
||||||
|
|
||||||
### Automatically discover databases
|
### Automatically discover databases
|
||||||
To scrape metrics from all databases on a database server, the database DSN's can be dynamically discovered via the
|
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 WHERE datallowconn = true AND datistemplate = false and datname != current_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 and datname != current_database()` is run for all configured DSN's. From the
|
||||||
result a new set of DSN's is created for which the metrics are scraped.
|
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.
|
In addition, the option `--exclude-databases` adds the possibily to filter the result from the auto discovery to discard databases you do not need.
|
||||||
@@ -285,3 +285,14 @@ GRANT SELECT ON postgres_exporter.pg_stat_statements TO postgres_exporter;
|
|||||||
> ```
|
> ```
|
||||||
> DATA_SOURCE_NAME=postgresql://postgres_exporter:password@localhost:5432/postgres?sslmode=disable
|
> DATA_SOURCE_NAME=postgresql://postgres_exporter:password@localhost:5432/postgres?sslmode=disable
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
```
|
||||||
|
# Run the unit tests
|
||||||
|
make test
|
||||||
|
# Start the test database with docker
|
||||||
|
docker run -p 5432:5432 -e POSTGRES_DB=circle_test -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=test -d postgres
|
||||||
|
# Run the integration tests
|
||||||
|
DATA_SOURCE_NAME='postgresql://postgres:test@localhost:5432/circle_test?sslmode=disable' GOOPTS='-v -tags integration' make test
|
||||||
|
```
|
||||||
|
|||||||
@@ -1149,7 +1149,9 @@ func ExcludeDatabases(s string) ExporterOpt {
|
|||||||
// IncludeDatabases allows to filter result from AutoDiscoverDatabases
|
// IncludeDatabases allows to filter result from AutoDiscoverDatabases
|
||||||
func IncludeDatabases(s string) ExporterOpt {
|
func IncludeDatabases(s string) ExporterOpt {
|
||||||
return func(e *Exporter) {
|
return func(e *Exporter) {
|
||||||
e.includeDatabases = strings.Split(s, ",")
|
if len(s) > 0 {
|
||||||
|
e.includeDatabases = strings.Split(s, ",")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,3 +162,16 @@ func (s *IntegrationSuite) TestExtendQueriesDoesntCrash(c *C) {
|
|||||||
// scrape the exporter and make sure it works
|
// scrape the exporter and make sure it works
|
||||||
exporter.scrape(ch)
|
exporter.scrape(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationSuite) TestAutoDiscoverDatabases(c *C) {
|
||||||
|
dsn := os.Getenv("DATA_SOURCE_NAME")
|
||||||
|
|
||||||
|
exporter := NewExporter(
|
||||||
|
strings.Split(dsn, ","),
|
||||||
|
)
|
||||||
|
c.Assert(exporter, NotNil)
|
||||||
|
|
||||||
|
dsns := exporter.discoverDatabaseDSNs()
|
||||||
|
|
||||||
|
c.Assert(len(dsns), Equals, 2)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user