Skip to content

Commit 8f8d220

Browse files
sysadmindSuperQ
andcommitted
cleanup and README
Signed-off-by: Joe Adams <[email protected]> Co-authored-by: Ben Kochie <[email protected]>
1 parent cc751b7 commit 8f8d220

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,36 @@ docker run \
2121
quay.io/prometheuscommunity/postgres-exporter
2222
```
2323

24+
## Multi-Target Support (BETA)
25+
**This Feature is in beta and may require changes in future releases. 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** and meant for users where it is impossible to install the exporter as a sidecar. For example SaaS-managed services.
28+
29+
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.
30+
31+
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.
32+
33+
## Configuration File
34+
35+
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`.
36+
37+
### auth_modules
38+
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.
39+
Currently only the `userpass` type is supported.
40+
41+
Example:
42+
```yaml
43+
auth_modules:
44+
foo1: # Set this to any name you want
45+
type: userpass
46+
userpass:
47+
username: first
48+
password: firstpass
49+
options:
50+
# options become key=value parameters of the DSN
51+
sslmode: disable
52+
```
53+
2454
## Building and running
2555
2656
git clone https://github.com/prometheus-community/postgres_exporter.git

cmd/postgres_exporter/main.go

-6
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

+6-14
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

config/config.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,24 @@ import (
2222

2323
"github.com/go-kit/log"
2424
"github.com/prometheus/client_golang/prometheus"
25+
"github.com/prometheus/client_golang/prometheus/promauto"
2526
"gopkg.in/yaml.v3"
2627
)
2728

2829
var (
29-
configReloadSuccess = prometheus.NewGauge(prometheus.GaugeOpts{
30+
configReloadSuccess = promauto.NewGauge(prometheus.GaugeOpts{
3031
Namespace: "postgres_exporter",
3132
Name: "config_last_reload_successful",
3233
Help: "Postgres exporter config loaded successfully.",
3334
})
3435

35-
configReloadSeconds = prometheus.NewGauge(prometheus.GaugeOpts{
36+
configReloadSeconds = promauto.NewGauge(prometheus.GaugeOpts{
3637
Namespace: "postgres_exporter",
3738
Name: "config_last_reload_success_timestamp_seconds",
3839
Help: "Timestamp of the last successful configuration reload.",
3940
})
4041
)
4142

42-
func init() {
43-
prometheus.MustRegister(configReloadSuccess)
44-
prometheus.MustRegister(configReloadSeconds)
45-
}
46-
4743
type Config struct {
4844
AuthModules map[string]AuthModule `yaml:"auth_modules"`
4945
}

0 commit comments

Comments
 (0)