Metrics Server support added for expvar. Refactored some methods.

This commit is contained in:
Musab Gültekin
2019-06-30 19:09:03 +03:00
parent ec4551a8a0
commit 7c383b175f
3 changed files with 29 additions and 15 deletions

View File

@ -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
}