@@ -6,7 +6,6 @@ package metrics
66import (
77 "fmt"
88 "net/http"
9- "time"
109
1110 "github.com/prometheus/client_golang/prometheus"
1211 "github.com/prometheus/client_golang/prometheus/promhttp"
@@ -44,22 +43,12 @@ func NewMetricsServer(addr string, connector RedisConnector, versionInfo Version
4443 }
4544 }
4645
47- // Scrape duration gauge — updated after each /metrics response is written,
48- // so it reports the duration of the previous scrape (not the current one).
49- // This is consistent with how node_exporter and similar exporters work.
50- scrapeDuration := prometheus .NewGauge (prometheus.GaugeOpts {
51- Name : "sonic_scrape_duration_seconds" ,
52- Help : "Duration of the last metrics scrape in seconds" ,
53- })
54- registry .MustRegister (scrapeDuration )
46+ // NOTE: Scrape duration is not emitted by this exporter. Prometheus records
47+ // scrape_duration_seconds server-side as part of every scrape automatically.
5548
5649 mux := http .NewServeMux ()
5750 handler := promhttp .HandlerFor (registry , promhttp.HandlerOpts {})
58- mux .Handle ("GET /metrics" , http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
59- start := time .Now ()
60- handler .ServeHTTP (w , r )
61- scrapeDuration .Set (time .Since (start ).Seconds ())
62- }))
51+ mux .Handle ("GET /metrics" , handler )
6352 mux .HandleFunc ("GET /healthz" , func (w http.ResponseWriter , r * http.Request ) {
6453 client , err := connector .Connect ("CONFIG_DB" )
6554 if err != nil {
0 commit comments