@@ -104,11 +104,10 @@ func NewExporter(logger *slog.Logger, m *MetricsConfiguration) *Exporter {
104
104
logger : logger ,
105
105
MetricsConfiguration : m ,
106
106
databases : databases ,
107
- lastScraped : map [string ]* time.Time {},
108
107
allConstLabels : allConstLabels ,
109
108
}
110
109
e .metricsToScrape = e .DefaultMetrics ()
111
-
110
+ e . initCache ()
112
111
return e
113
112
}
114
113
@@ -253,7 +252,7 @@ func (e *Exporter) scrapeDatabase(ch chan<- prometheus.Metric, errChan chan<- er
253
252
go func () {
254
253
// If the metric doesn't need to be scraped, send the cached values
255
254
if ! isScrapeMetric {
256
- metric . sendAll (ch )
255
+ d . MetricsCache . SendAll (ch , metric )
257
256
errChan <- nil
258
257
return
259
258
}
@@ -416,6 +415,7 @@ func (e *Exporter) reloadMetrics() {
416
415
} else {
417
416
e .logger .Debug ("No custom metrics defined." )
418
417
}
418
+ e .initCache ()
419
419
}
420
420
421
421
// ScrapeMetric is an interface method to call scrapeGenericValues using Metric struct values
@@ -475,9 +475,9 @@ func (e *Exporter) scrapeGenericValues(d *Database, ch chan<- prometheus.Metric,
475
475
}
476
476
buckets [lelimit ] = counter
477
477
}
478
- m . cacheAndSend (ch , prometheus .MustNewConstHistogram (desc , count , value , buckets , labelsValues ... ))
478
+ d . MetricsCache . CacheAndSend (ch , m , prometheus .MustNewConstHistogram (desc , count , value , buckets , labelsValues ... ))
479
479
} else {
480
- m . cacheAndSend (ch , prometheus .MustNewConstMetric (desc , getMetricType (metric , m .MetricsType ), value , labelsValues ... ))
480
+ d . MetricsCache . CacheAndSend (ch , m , prometheus .MustNewConstMetric (desc , getMetricType (metric , m .MetricsType ), value , labelsValues ... ))
481
481
}
482
482
// If no labels, use metric name
483
483
} else {
@@ -509,9 +509,9 @@ func (e *Exporter) scrapeGenericValues(d *Database, ch chan<- prometheus.Metric,
509
509
}
510
510
buckets [lelimit ] = counter
511
511
}
512
- m . cacheAndSend (ch , prometheus .MustNewConstHistogram (desc , count , value , buckets ))
512
+ d . MetricsCache . CacheAndSend (ch , m , prometheus .MustNewConstHistogram (desc , count , value , buckets ))
513
513
} else {
514
- m . cacheAndSend (ch , prometheus .MustNewConstMetric (desc , getMetricType (metric , m .MetricsType ), value ))
514
+ d . MetricsCache . CacheAndSend (ch , m , prometheus .MustNewConstMetric (desc , getMetricType (metric , m .MetricsType ), value ))
515
515
}
516
516
}
517
517
metricsCount ++
@@ -578,6 +578,12 @@ func (e *Exporter) generatePrometheusMetrics(d *Database, parse func(row map[str
578
578
return nil
579
579
}
580
580
581
+ func (e * Exporter ) initCache () {
582
+ for _ , d := range e .databases {
583
+ d .initCache (e .metricsToScrape .Metric )
584
+ }
585
+ }
586
+
581
587
func getMetricType (metricType string , metricsType map [string ]string ) prometheus.ValueType {
582
588
var strToPromType = map [string ]prometheus.ValueType {
583
589
"gauge" : prometheus .GaugeValue ,
0 commit comments