From 4c05aec3d4b76de478165101f11a5af237377d2a Mon Sep 17 00:00:00 2001 From: wangqing Date: Fri, 10 Oct 2025 16:54:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B1=8F=E8=94=BD=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=9C=AC=E8=BA=AB=E6=8C=87=E6=A0=87=E5=92=8C?= =?UTF-8?q?GC=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangqing --- server.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 250fde3..6436601 100644 --- a/server.go +++ b/server.go @@ -5,6 +5,7 @@ import ( "log" "net/http" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -24,8 +25,12 @@ func NewServer(config *Config, collector *LibvirtCollector) *Server { // SetupHandlers sets up the HTTP handlers func (s *Server) SetupHandlers() { - // Metrics endpoint - http.Handle(s.config.MetricsPath, promhttp.Handler()) + // Create a custom registry and register only our collector + registry := prometheus.NewRegistry() + registry.MustRegister(s.collector) + + // Metrics endpoint using custom registry + http.Handle(s.config.MetricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{})) // Root endpoint http.HandleFunc("/", s.rootHandler) -- Gitee