cleanup and README
Signed-off-by: Joe Adams <github@joeadams.io> Co-authored-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
30
README.md
30
README.md
@@ -21,6 +21,36 @@ docker run \
|
|||||||
quay.io/prometheuscommunity/postgres-exporter
|
quay.io/prometheuscommunity/postgres-exporter
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Multi-Target Support (BETA)
|
||||||
|
**This Feature is in beta and may require changes in future releases. Feedback is welcome.**
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Configuration File
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
### auth_modules
|
||||||
|
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.
|
||||||
|
Currently only the `userpass` type is supported.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```yaml
|
||||||
|
auth_modules:
|
||||||
|
foo1: # Set this to any name you want
|
||||||
|
type: userpass
|
||||||
|
userpass:
|
||||||
|
username: first
|
||||||
|
password: firstpass
|
||||||
|
options:
|
||||||
|
# options become key=value parameters of the DSN
|
||||||
|
sslmode: disable
|
||||||
|
```
|
||||||
|
|
||||||
## Building and running
|
## Building and running
|
||||||
|
|
||||||
git clone https://github.com/prometheus-community/postgres_exporter.git
|
git clone https://github.com/prometheus-community/postgres_exporter.git
|
||||||
|
|||||||
@@ -102,12 +102,6 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(@sysadmind): Remove this with multi-target support
|
|
||||||
// if len(dsn) == 0 {
|
|
||||||
// level.Error(logger).Log("msg", "Couldn't find environment variables describing the datasource to use")
|
|
||||||
// os.Exit(1)
|
|
||||||
// }
|
|
||||||
|
|
||||||
opts := []ExporterOpt{
|
opts := []ExporterOpt{
|
||||||
DisableDefaultMetrics(*disableDefaultMetrics),
|
DisableDefaultMetrics(*disableDefaultMetrics),
|
||||||
DisableSettingsMetrics(*disableSettingsMetrics),
|
DisableSettingsMetrics(*disableSettingsMetrics),
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func handleProbe(logger log.Logger) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Timeout
|
// TODO(@sysadmind): Timeout
|
||||||
|
|
||||||
probeSuccessGauge := prometheus.NewGauge(prometheus.GaugeOpts{
|
probeSuccessGauge := prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "probe_success",
|
Name: "probe_success",
|
||||||
@@ -86,23 +86,15 @@ func handleProbe(logger log.Logger) http.HandlerFunc {
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(@sysadmind): Remove the registry.MustRegister() call below and instead handle the collection here. That will allow
|
||||||
|
// for the passing of context, handling of timeouts, and more control over the collection.
|
||||||
|
// The current NewProbeCollector() implementation relies on the MustNewConstMetric() call to create the metrics which is not
|
||||||
|
// ideal to use without the registry.MustRegister() call.
|
||||||
_ = ctx
|
_ = ctx
|
||||||
|
|
||||||
// TODO: Which way should this be? Register or handle the collection manually?
|
|
||||||
// Also, what about the context?
|
|
||||||
|
|
||||||
// Option 1: Register the collector
|
|
||||||
registry.MustRegister(pc)
|
registry.MustRegister(pc)
|
||||||
|
|
||||||
// Option 2: Handle the collection manually. This allows us to collect duration metrics.
|
|
||||||
// The collectors themselves already support their own duration metrics.
|
|
||||||
// err = pc.Update(ctx)
|
|
||||||
// if err != nil {
|
|
||||||
// probeSuccessGauge.Set(0)
|
|
||||||
// } else {
|
|
||||||
// probeSuccessGauge.Set(1)
|
|
||||||
// }
|
|
||||||
|
|
||||||
duration := time.Since(start).Seconds()
|
duration := time.Since(start).Seconds()
|
||||||
probeDurationGauge.Set(duration)
|
probeDurationGauge.Set(duration)
|
||||||
|
|
||||||
|
|||||||
@@ -22,28 +22,24 @@ import (
|
|||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
configReloadSuccess = prometheus.NewGauge(prometheus.GaugeOpts{
|
configReloadSuccess = promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: "postgres_exporter",
|
Namespace: "postgres_exporter",
|
||||||
Name: "config_last_reload_successful",
|
Name: "config_last_reload_successful",
|
||||||
Help: "Postgres exporter config loaded successfully.",
|
Help: "Postgres exporter config loaded successfully.",
|
||||||
})
|
})
|
||||||
|
|
||||||
configReloadSeconds = prometheus.NewGauge(prometheus.GaugeOpts{
|
configReloadSeconds = promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: "postgres_exporter",
|
Namespace: "postgres_exporter",
|
||||||
Name: "config_last_reload_success_timestamp_seconds",
|
Name: "config_last_reload_success_timestamp_seconds",
|
||||||
Help: "Timestamp of the last successful configuration reload.",
|
Help: "Timestamp of the last successful configuration reload.",
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
prometheus.MustRegister(configReloadSuccess)
|
|
||||||
prometheus.MustRegister(configReloadSeconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AuthModules map[string]AuthModule `yaml:"auth_modules"`
|
AuthModules map[string]AuthModule `yaml:"auth_modules"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user