Skip to content

Commit

Permalink
sq
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Apr 3, 2024
1 parent 8c06baa commit 1bae13a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
)

//nolint:gochecknoglobals
Expand All @@ -11,3 +12,10 @@ var reg = prometheus.NewRegistry()
func RegisterMetric(c prometheus.Collector) {
_ = reg.Register(c)
}

func StartCollection() {
_ = reg.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
_ = reg.Register(collectors.NewGoCollector())

registerEventListeners()
}
6 changes: 0 additions & 6 deletions metrics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/0xERR0R/blocky/service"
"github.com/0xERR0R/blocky/util"
"github.com/go-chi/chi/v5"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

Expand All @@ -25,11 +24,6 @@ func NewService(cfg config.MetricsService, metricsCfg config.Metrics) *Service {
return new(Service)
}

_ = reg.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
_ = reg.Register(collectors.NewGoCollector())

registerEventListeners()

s := &Service{
HTTPInfo: service.HTTPInfo{
Info: service.Info{
Expand Down
5 changes: 5 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func NewServer(ctx context.Context, cfg *config.Config) (server *Server, err err
return nil, err
}

if cfg.Prometheus.Enable {
// Must happen before resolver initialization
metrics.StartCollection()
}

bootstrap, err := resolver.NewBootstrap(ctx, cfg)
if err != nil {
return nil, err
Expand Down

0 comments on commit 1bae13a

Please sign in to comment.