@@ -198,7 +198,7 @@ func init() {
198
198
prometheus .MustRegister (version .NewCollector ("mysqld_exporter" ))
199
199
}
200
200
201
- func newHandler (cfg * webAuth , db * sql.DB , scrapers []collector.Scraper , stats * collector.Stats ) http.HandlerFunc {
201
+ func newHandler (cfg * webAuth , db * sql.DB , scrapers []collector.Scraper , stats * collector.Stats , defaultGatherer bool ) http.HandlerFunc {
202
202
return func (w http.ResponseWriter , r * http.Request ) {
203
203
filteredScrapers := scrapers
204
204
params := r .URL .Query ()["collect[]" ]
@@ -232,10 +232,12 @@ func newHandler(cfg *webAuth, db *sql.DB, scrapers []collector.Scraper, stats *c
232
232
registry := prometheus .NewRegistry ()
233
233
registry .MustRegister (collector .New (db , filteredScrapers , stats ))
234
234
235
- gatherers := prometheus.Gatherers {
236
- prometheus . DefaultGatherer ,
237
- registry ,
235
+ gatherers := prometheus.Gatherers {}
236
+ if defaultGatherer {
237
+ gatherers = append ( gatherers , prometheus . DefaultGatherer )
238
238
}
239
+ gatherers = append (gatherers , registry )
240
+
239
241
// Delegate http serving to Prometheus client library, which will call collector.Collect.
240
242
h := promhttp .HandlerFor (gatherers , promhttp.HandlerOpts {
241
243
// mysqld_exporter has multiple collectors, if one fails,
@@ -361,9 +363,9 @@ func main() {
361
363
362
364
// Defines what to scrape in each resolution.
363
365
hr , mr , lr := enabledScrapers (scraperFlags )
364
- mux .Handle (* metricPath + "-hr" , newHandler (cfg , db , hr , collector .NewStats ("hr" )))
365
- mux .Handle (* metricPath + "-mr" , newHandler (cfg , db , mr , collector .NewStats ("mr" )))
366
- mux .Handle (* metricPath + "-lr" , newHandler (cfg , db , lr , collector .NewStats ("lr" )))
366
+ mux .Handle (* metricPath + "-hr" , newHandler (cfg , db , hr , collector .NewStats ("hr" ), true ))
367
+ mux .Handle (* metricPath + "-mr" , newHandler (cfg , db , mr , collector .NewStats ("mr" ), false ))
368
+ mux .Handle (* metricPath + "-lr" , newHandler (cfg , db , lr , collector .NewStats ("lr" ), false ))
367
369
368
370
// Log which scrapers are enabled.
369
371
if len (hr ) > 0 {
0 commit comments