Skip to content

Commit d2674e6

Browse files
committed
cleanup and README
Signed-off-by: Joe Adams <[email protected]>
1 parent 5ced18f commit d2674e6

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,34 @@ docker run \
2121
quay.io/prometheuscommunity/postgres-exporter
2222
```
2323

24+
## Multi-Target Support (BETA)
25+
**This Feature is in beta and may not be suitable for production use. Feedback is welcome.**
26+
27+
This exporter supports the [multi-target pattern](https://prometheus.io/docs/guides/multi-target-exporter/). This allows running a single instance of this exporter for multiple postgres targets. Using the milti-target funcationality of this exporter is **optional**. To use the multi-target functionality, send an http request to the endpoint `/probe?target=foo:5432` where target is set to the DSN of the postgres instance to scrape metrics from.
28+
29+
To avoid putting sensitive information like username and password in the URL, preconfigured auth modules are supported via the [auth_modules](#auth_modules) section of the config file. auth_modules for DSNs can be used with the `/probe` endpoint by specifying the `?auth_module=foo` http parameter.
30+
31+
## Configuration File
32+
33+
The configuration file controls the behavior of the exporter. It can be set using the `--config.file` command line flag and defaults to `postres_exporter.yml`.
34+
35+
### auth_modules
36+
This section defines preset authentication and connection parameters for use in the [multi-target endpoint](#multi-target-support-beta). `auth_modules` is a map of modules with the key being the identifier which can be used in the `/probe` endpoint.
37+
Currently only the `userpass` type is supported.
38+
39+
Example:
40+
```yaml
41+
auth_modules:
42+
foo1: # Set this to any name you want
43+
type: userpass
44+
userpass:
45+
username: first
46+
password: firstpass
47+
options:
48+
# options become key=value parameters of the DSN
49+
sslmode: disable
50+
```
51+
2452
## Building and running
2553
2654
git clone https://github.com/prometheus-community/postgres_exporter.git

cmd/postgres_exporter/main.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ func main() {
102102
os.Exit(1)
103103
}
104104

105-
// TODO(@sysadmind): Remove this with multi-target support
106-
// if len(dsn) == 0 {
107-
// level.Error(logger).Log("msg", "Couldn't find environment variables describing the datasource to use")
108-
// os.Exit(1)
109-
// }
110-
111105
opts := []ExporterOpt{
112106
DisableDefaultMetrics(*disableDefaultMetrics),
113107
DisableSettingsMetrics(*disableSettingsMetrics),

cmd/postgres_exporter/probe.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func handleProbe(logger log.Logger) http.HandlerFunc {
6060
return
6161
}
6262

63-
// TODO: Timeout
63+
// TODO(@sysadmind): Timeout
6464

6565
probeSuccessGauge := prometheus.NewGauge(prometheus.GaugeOpts{
6666
Name: "probe_success",
@@ -86,23 +86,15 @@ func handleProbe(logger log.Logger) http.HandlerFunc {
8686
http.Error(w, err.Error(), http.StatusInternalServerError)
8787
return
8888
}
89-
_ = ctx
9089

91-
// TODO: Which way should this be? Register or handle the collection manually?
92-
// Also, what about the context?
90+
// TODO(@sysadmind): Remove the registry.MustRegister() call below and instead handle the collection here. That will allow
91+
// for the passing of context, handling of timeouts, and more control over the collection.
92+
// The current NewProbeCollector() implementation relies on the MustNewConstMetric() call to create the metrics which is not
93+
// ideal to use without the registry.MustRegister() call.
94+
_ = ctx
9395

94-
// Option 1: Register the collector
9596
registry.MustRegister(pc)
9697

97-
// Option 2: Handle the collection manually. This allows us to collect duration metrics.
98-
// The collectors themselves already support their own duration metrics.
99-
// err = pc.Update(ctx)
100-
// if err != nil {
101-
// probeSuccessGauge.Set(0)
102-
// } else {
103-
// probeSuccessGauge.Set(1)
104-
// }
105-
10698
duration := time.Since(start).Seconds()
10799
probeDurationGauge.Set(duration)
108100

0 commit comments

Comments
 (0)