Add pg_database collector

Converts the pg_database metrics from queries.yaml to a built in collector. This is enabled by default because it is not likely to be a performance problem and likely very useful data.

Signed-off-by: Joe Adams <github@joeadams.io>
This commit is contained in:
Joe Adams
2022-02-09 21:28:40 -05:00
parent 3880df4f64
commit 21a19ed252
4 changed files with 81 additions and 12 deletions

View File

@@ -14,13 +14,16 @@
package main
import (
"context"
"database/sql"
"fmt"
"log"
"sync"
"time"
"github.com/blang/semver"
"github.com/go-kit/log/level"
"github.com/prometheus-community/postgres_exporter/collector"
"github.com/prometheus/client_golang/prometheus"
)
@@ -128,6 +131,17 @@ func (s *Server) Scrape(ch chan<- prometheus.Metric, disableSettingsMetrics bool
err = fmt.Errorf("queryNamespaceMappings returned %d errors", len(errMap))
}
{
pgdb := collector.NewPGDatabaseCollector()
metrics, err := pgdb.Update(context.TODO(), s.db, s.String())
if err != nil {
log.Printf("Failed to scrape pg_database metrics: %s", err)
}
for _, m := range metrics {
ch <- m
}
}
return err
}