blocky/metrics/metrics.go

29 lines
805 B
Go
Raw Normal View History

package metrics
import (
2021-08-25 22:06:34 +02:00
"github.com/0xERR0R/blocky/config"
2021-12-24 22:56:41 +01:00
"github.com/go-chi/chi/v5"
"github.com/prometheus/client_golang/prometheus"
2021-06-16 22:30:52 +02:00
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
//nolint:gochecknoglobals
var reg = prometheus.NewRegistry()
// RegisterMetric registers prometheus collector
func RegisterMetric(c prometheus.Collector) {
_ = reg.Register(c)
}
// Start starts prometheus endpoint
func Start(router *chi.Mux, cfg config.Metrics) {
if cfg.Enable {
2021-06-16 22:30:52 +02:00
_ = reg.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
_ = reg.Register(collectors.NewGoCollector())
2020-04-08 23:03:07 +02:00
router.Handle(cfg.Path, promhttp.InstrumentMetricHandler(reg,
promhttp.HandlerFor(reg, promhttp.HandlerOpts{})))
}
}