diff --git a/cmd/postgres_exporter/pg_setting.go b/cmd/postgres_exporter/pg_setting.go index 4b0e2124f..78a974abb 100644 --- a/cmd/postgres_exporter/pg_setting.go +++ b/cmd/postgres_exporter/pg_setting.go @@ -18,11 +18,17 @@ import ( "math" "strconv" "strings" + "sync" "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" ) +var ( + // cache the first server setting when there are multiple servers + shortDescCache sync.Map +) + // Query the pg_settings view containing runtime variables func querySettings(ch chan<- prometheus.Metric, server *Server) error { level.Debug(logger).Log("msg", "Querying pg_setting view", "server", server) @@ -46,6 +52,15 @@ func querySettings(ch chan<- prometheus.Metric, server *Server) error { return fmt.Errorf("Error retrieving rows on %q: %s %v", server, namespace, err) } + // once the first server setting shortDesc cached, the other server re-use the first cache + if v, ok := shortDescCache.Load(s.name); !ok { + shortDescCache.Store(s.name, s.shortDesc) + } else { + if shortDesc, ok := v.(string); ok { + s.shortDesc = shortDesc + } + } + ch <- s.metric(server.labels) }