You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-12-21 04:00:58 +03:00
Adjust collector to use separate connection per scrape (#931)
Fixes #921 Signed-off-by: Joe Adams <github@joeadams.io>
This commit is contained in:
@@ -167,19 +167,22 @@ func (p PostgresCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (p PostgresCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
ctx := context.TODO()
|
||||
|
||||
// copy the instance so that concurrent scrapes have independent instances
|
||||
inst := p.instance.copy()
|
||||
|
||||
// Set up the database connection for the collector.
|
||||
err := p.instance.setup()
|
||||
err := inst.setup()
|
||||
if err != nil {
|
||||
level.Error(p.logger).Log("msg", "Error opening connection to database", "err", err)
|
||||
return
|
||||
}
|
||||
defer p.instance.Close()
|
||||
defer inst.Close()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(p.Collectors))
|
||||
for name, c := range p.Collectors {
|
||||
go func(name string, c Collector) {
|
||||
execute(ctx, name, c, p.instance, ch, p.logger)
|
||||
execute(ctx, name, c, inst, ch, p.logger)
|
||||
wg.Done()
|
||||
}(name, c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user