@@ -104,11 +104,10 @@ func NewExporter(logger *slog.Logger, m *MetricsConfiguration) *Exporter {
104104 logger : logger ,
105105 MetricsConfiguration : m ,
106106 databases : databases ,
107- lastScraped : map [string ]* time.Time {},
108107 allConstLabels : allConstLabels ,
109108 }
110109 e .metricsToScrape = e .DefaultMetrics ()
111-
110+ e . initCache ()
112111 return e
113112}
114113
@@ -253,7 +252,7 @@ func (e *Exporter) scrapeDatabase(ch chan<- prometheus.Metric, errChan chan<- er
253252 go func () {
254253 // If the metric doesn't need to be scraped, send the cached values
255254 if ! isScrapeMetric {
256- metric . sendAll (ch )
255+ d . MetricsCache . SendAll (ch , metric )
257256 errChan <- nil
258257 return
259258 }
@@ -416,6 +415,7 @@ func (e *Exporter) reloadMetrics() {
416415 } else {
417416 e .logger .Debug ("No custom metrics defined." )
418417 }
418+ e .initCache ()
419419}
420420
421421// 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,
475475 }
476476 buckets [lelimit ] = counter
477477 }
478- m . cacheAndSend (ch , prometheus .MustNewConstHistogram (desc , count , value , buckets , labelsValues ... ))
478+ d . MetricsCache . CacheAndSend (ch , m , prometheus .MustNewConstHistogram (desc , count , value , buckets , labelsValues ... ))
479479 } 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 ... ))
481481 }
482482 // If no labels, use metric name
483483 } else {
@@ -509,9 +509,9 @@ func (e *Exporter) scrapeGenericValues(d *Database, ch chan<- prometheus.Metric,
509509 }
510510 buckets [lelimit ] = counter
511511 }
512- m . cacheAndSend (ch , prometheus .MustNewConstHistogram (desc , count , value , buckets ))
512+ d . MetricsCache . CacheAndSend (ch , m , prometheus .MustNewConstHistogram (desc , count , value , buckets ))
513513 } 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 ))
515515 }
516516 }
517517 metricsCount ++
@@ -578,6 +578,12 @@ func (e *Exporter) generatePrometheusMetrics(d *Database, parse func(row map[str
578578 return nil
579579}
580580
581+ func (e * Exporter ) initCache () {
582+ for _ , d := range e .databases {
583+ d .initCache (e .metricsToScrape .Metric )
584+ }
585+ }
586+
581587func getMetricType (metricType string , metricsType map [string ]string ) prometheus.ValueType {
582588 var strToPromType = map [string ]prometheus.ValueType {
583589 "gauge" : prometheus .GaugeValue ,
0 commit comments