You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
watchtower/pkg/api/metrics.go

33 lines
701 B
Go

package api
import (
"github.com/containrrr/watchtower/pkg/metrics"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// MetricsHandler is a HTTP handler for serving metric data
type MetricsHandler struct {
Path string
Handle http.HandlerFunc
Metrics *metrics.Metrics
}
// NewMetricsHandler is a factory function creating a new Metrics instance
func NewMetricsHandler() *MetricsHandler {
m := metrics.Default()
handler := promhttp.Handler()
return &MetricsHandler{
Path: "/v1/metrics",
Handle: handler.ServeHTTP,
Metrics: m,
}
}
func MetricsEndpoint() (path string, handler http.HandlerFunc) {
mh := NewMetricsHandler()
return mh.Path, mh.Handle
}