status-go/metrics/metrics.go
Jakub Sokołowski 4fe317917e create a /metrics endpoint for Prometheus
Signed-off-by: Jakub Sokołowski <jakub@status.im>
2019-10-11 10:55:08 +02:00

33 lines
685 B
Go

package metrics
import (
"fmt"
"net/http"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/prometheus"
)
// Server runs and controls a HTTP pprof interface.
type Server struct {
server *http.Server
}
func NewMetricsServer(port int, r metrics.Registry) *Server {
mux := http.NewServeMux()
mux.Handle("/metrics", prometheus.Handler(r))
p := Server{
server: &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: mux,
},
}
return &p
}
// Listen starts the HTTP server in the background.
func (p *Server) Listen() {
log.Info("metrics server stopped", "err", p.server.ListenAndServe())
}