2020-03-06 23:00:14 +01:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2021-08-25 22:06:34 +02:00
|
|
|
"github.com/0xERR0R/blocky/config"
|
2020-03-06 23:00:14 +01:00
|
|
|
|
2021-12-24 22:56:41 +01:00
|
|
|
"github.com/go-chi/chi/v5"
|
2020-03-06 23:00:14 +01:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-06-16 22:30:52 +02:00
|
|
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
2020-03-06 23:00:14 +01:00
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
)
|
|
|
|
|
2022-11-29 21:58:26 +01:00
|
|
|
//nolint:gochecknoglobals
|
2020-03-06 23:00:14 +01:00
|
|
|
var reg = prometheus.NewRegistry()
|
|
|
|
|
2021-02-26 13:45:57 +01:00
|
|
|
// RegisterMetric registers prometheus collector
|
2020-03-06 23:00:14 +01:00
|
|
|
func RegisterMetric(c prometheus.Collector) {
|
|
|
|
_ = reg.Register(c)
|
|
|
|
}
|
|
|
|
|
2021-02-26 13:45:57 +01:00
|
|
|
// Start starts prometheus endpoint
|
2023-12-20 21:38:33 +01:00
|
|
|
func Start(router *chi.Mux, cfg config.Metrics) {
|
2020-03-06 23:00:14 +01:00
|
|
|
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,
|
2020-03-06 23:00:14 +01:00
|
|
|
promhttp.HandlerFor(reg, promhttp.HandlerOpts{})))
|
|
|
|
}
|
|
|
|
}
|