2021-01-06 22:28:32 +01:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
|
|
import (
|
2023-10-04 12:17:38 +02:00
|
|
|
"github.com/nicholas-fedor/watchtower/pkg/metrics"
|
2021-01-06 22:28:32 +01:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Handler is an HTTP handle for serving metric data
|
|
|
|
|
type Handler struct {
|
|
|
|
|
Path string
|
|
|
|
|
Handle http.HandlerFunc
|
|
|
|
|
Metrics *metrics.Metrics
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New is a factory function creating a new Metrics instance
|
|
|
|
|
func New() *Handler {
|
|
|
|
|
m := metrics.Default()
|
|
|
|
|
handler := promhttp.Handler()
|
|
|
|
|
|
|
|
|
|
return &Handler{
|
|
|
|
|
Path: "/v1/metrics",
|
|
|
|
|
Handle: handler.ServeHTTP,
|
|
|
|
|
Metrics: m,
|
|
|
|
|
}
|
|
|
|
|
}
|