Skip to content

Commit

Permalink
Export metrics registry
Browse files Browse the repository at this point in the history
Export the custom metrics registry from the metrics package so it can be
used with promauto in other packages.

Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ committed Aug 28, 2024
1 parent eb75401 commit 23ded2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
)

//nolint:gochecknoglobals
var reg = prometheus.NewRegistry()
var Reg = prometheus.NewRegistry()

// RegisterMetric registers prometheus collector
func RegisterMetric(c prometheus.Collector) {
_ = reg.Register(c)
_ = Reg.Register(c)
}

// Start starts prometheus endpoint
func Start(router *chi.Mux, cfg config.Metrics) {
if cfg.Enable {
_ = reg.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
_ = reg.Register(collectors.NewGoCollector())
router.Handle(cfg.Path, promhttp.InstrumentMetricHandler(reg,
promhttp.HandlerFor(reg, promhttp.HandlerOpts{})))
_ = Reg.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
_ = Reg.Register(collectors.NewGoCollector())
router.Handle(cfg.Path, promhttp.InstrumentMetricHandler(Reg,
promhttp.HandlerFor(Reg, promhttp.HandlerOpts{})))
}
}
5 changes: 3 additions & 2 deletions resolver/caching_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/0xERR0R/blocky/cache/expirationcache"
"github.com/0xERR0R/blocky/config"
"github.com/0xERR0R/blocky/evt"
"github.com/0xERR0R/blocky/metrics"
"github.com/0xERR0R/blocky/model"
"github.com/0xERR0R/blocky/redis"
"github.com/0xERR0R/blocky/util"
Expand All @@ -24,13 +25,13 @@ const defaultCachingCleanUpInterval = 5 * time.Second

//nolint:gochecknoglobals
var (
cacheHits = promauto.NewCounter(
cacheHits = promauto.With(metrics.Reg).NewCounter(
prometheus.CounterOpts{
Name: "blocky_cache_hits_total",
Help: "Cache hit counter",
},
)
cacheMisses = promauto.NewCounter(
cacheMisses = promauto.With(metrics.Reg).NewCounter(
prometheus.CounterOpts{
Name: "blocky_cache_misses_total",
Help: "Cache miss counter",
Expand Down

0 comments on commit 23ded2f

Please # to comment.