You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-08-14 01:02:26 +03:00
Fix exclude-databases for collector package
The pg_database collector was not respecting the --exclude-databases flag and causing problems where databases were not accessible. This now respects the list of databases to exclude. - Adjusts the Collector create func to take a config struct instead of a logger. This allows more changes like this in the future. I figured we would need to do this at some point but I wasn't sure if we could hold off. - Split the database size collection to a separate query when database is not excluded. - Comment some probe code that was not useful/accurate Signed-off-by: Joe Adams <github@joeadams.io>
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
@@ -101,13 +103,16 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
excludedDatabases := strings.Split(*excludeDatabases, ",")
|
||||
logger.Log("msg", "Excluded databases", "databases", fmt.Sprintf("%v", excludedDatabases))
|
||||
|
||||
opts := []ExporterOpt{
|
||||
DisableDefaultMetrics(*disableDefaultMetrics),
|
||||
DisableSettingsMetrics(*disableSettingsMetrics),
|
||||
AutoDiscoverDatabases(*autoDiscoverDatabases),
|
||||
WithUserQueriesPath(*queriesPath),
|
||||
WithConstantLabels(*constantLabelsList),
|
||||
ExcludeDatabases(*excludeDatabases),
|
||||
ExcludeDatabases(excludedDatabases),
|
||||
IncludeDatabases(*includeDatabases),
|
||||
}
|
||||
|
||||
@@ -128,6 +133,7 @@ func main() {
|
||||
|
||||
pe, err := collector.NewPostgresCollector(
|
||||
logger,
|
||||
excludedDatabases,
|
||||
dsn,
|
||||
[]string{},
|
||||
)
|
||||
@@ -143,7 +149,7 @@ func main() {
|
||||
w.Write(landingPage) // nolint: errcheck
|
||||
})
|
||||
|
||||
http.HandleFunc("/probe", handleProbe(logger))
|
||||
http.HandleFunc("/probe", handleProbe(logger, excludedDatabases))
|
||||
|
||||
srv := &http.Server{}
|
||||
if err := web.ListenAndServe(srv, webConfig, logger); err != nil {
|
||||
|
Reference in New Issue
Block a user