mirror of https://github.com/0xERR0R/blocky.git
35 lines
724 B
Go
35 lines
724 B
Go
package metrics
|
|
|
|
import (
|
|
"blocky/config"
|
|
|
|
"github.com/go-chi/chi"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
// nolint
|
|
var reg = prometheus.NewRegistry()
|
|
|
|
// nolint
|
|
var enabled bool
|
|
|
|
func RegisterMetric(c prometheus.Collector) {
|
|
_ = reg.Register(c)
|
|
}
|
|
|
|
func Start(router *chi.Mux, cfg config.PrometheusConfig) {
|
|
enabled = cfg.Enable
|
|
|
|
if cfg.Enable {
|
|
reg.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
|
|
reg.MustRegister(prometheus.NewGoCollector())
|
|
router.Handle(cfg.Path, promhttp.InstrumentMetricHandler(reg,
|
|
promhttp.HandlerFor(reg, promhttp.HandlerOpts{})))
|
|
}
|
|
}
|
|
|
|
func IsEnabled() bool {
|
|
return enabled
|
|
}
|