1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-08-14 01:02:26 +03:00

Add collector interface

Uses node_exporter style collector registration

Signed-off-by: Joe Adams <github@joeadams.io>
This commit is contained in:
Joe Adams
2022-02-14 21:12:27 -05:00
parent 1981623d9d
commit c3b0206369
5 changed files with 342 additions and 28 deletions

View File

@@ -19,6 +19,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/postgres_exporter/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
@@ -114,6 +115,13 @@ func main() {
prometheus.MustRegister(exporter)
pe, err := collector.NewPostgresCollector(logger, dsn)
if err != nil {
level.Error(logger).Log("msg", "Failed to create PostgresCollector", "err", err.Error())
os.Exit(1)
}
prometheus.MustRegister(pe)
http.Handle(*metricPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=UTF-8") // nolint: errcheck