Metrics Server support added for expvar. Refactored some methods.
This commit is contained in:
@ -6,6 +6,8 @@ import (
|
||||
"github.com/go-kit/kit/metrics/expvar"
|
||||
"github.com/go-kit/kit/metrics/prometheus"
|
||||
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Type represents metrics Types
|
||||
@ -66,3 +68,17 @@ func NewMetrics(metricsType Type) *Metrics {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// StartMetricsServer starts server that handles metrics
|
||||
// Prometheus: http://localhost:2112/metrics
|
||||
// Expvar : http://localhost:2112/debug/vars
|
||||
func StartMetricsServer(metricsType Type) *http.Server {
|
||||
if metricsType == Prometheus {
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
}
|
||||
server := &http.Server{Addr: ":2112"}
|
||||
go func() {
|
||||
server.ListenAndServe()
|
||||
}()
|
||||
return server
|
||||
}
|
||||
|
Reference in New Issue
Block a user