github.com/amazechain/amc@v0.1.3/internal/metrics/prometheus/exp.go (about)

     1  package prometheus
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/amazechain/amc/log"
     6  	"net/http"
     7  )
     8  
     9  var EnabledExpensive = false
    10  
    11  // Setup starts a dedicated metrics server at the given address.
    12  // This function enables metrics reporting separate from pprof.
    13  func Setup(address string, log log.Logger) *http.ServeMux {
    14  	prometheusMux := http.NewServeMux()
    15  
    16  	prometheusMux.Handle("/debug/metrics/prometheus", Handler(DefaultRegistry))
    17  
    18  	promServer := &http.Server{
    19  		Addr:    address,
    20  		Handler: prometheusMux,
    21  	}
    22  
    23  	go func() {
    24  		if err := promServer.ListenAndServe(); err != nil {
    25  			log.Error("Failure in running Prometheus server", "err", err)
    26  		}
    27  	}()
    28  
    29  	log.Info("Enabling metrics export to prometheus", "path", fmt.Sprintf("http://%s/debug/metrics/prometheus", address))
    30  
    31  	return prometheusMux
    32  }