Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ The following environment variables configure the exporter:
* `DATA_SOURCE_NAME`
the default legacy format. Accepts URI form and key=value form arguments. The
URI may contain the username and password to connect with.

* `DATA_SOURCE_NAME_FILE`
The same as above but reads the URI from a file.

* `DATA_SOURCE_URI`
an alternative to `DATA_SOURCE_NAME` which exclusively accepts the hostname
Expand Down
10 changes: 10 additions & 0 deletions cmd/postgres_exporter/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func getDataSources() ([]string, error) {
return strings.Split(dsn, ","), nil
}

dataSourceNameFile := os.Getenv("DATA_SOURCE_NAME_FILE")
if len(dataSourceNameFile) != 0 {
fileContents, err := ioutil.ReadFile(dataSourceNameFile)
if err != nil {
return nil, fmt.Errorf("failed loading data source name file %s: %s", dataSourceNameFile, err.Error())
}
dsnContent := strings.TrimSpace(string(fileContents))
return strings.Split(dsnContent, ","), nil
}

var user, pass, uri string

dataSourceUserFile := os.Getenv("DATA_SOURCE_USER_FILE")
Expand Down