diff options
author | Wolfy-J <[email protected]> | 2019-06-27 13:35:16 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-06-27 13:35:16 +0300 |
commit | 1ba7781dd4bb9767759fa596d3d7209497aaf37f (patch) | |
tree | fc047874eb51d6014120eb695e932ef47436e485 /service/metrics/service.go | |
parent | 11870a2df3ccd8f79f131354ba106e557c248b48 (diff) |
more tests, isolated prometheus instance
Diffstat (limited to 'service/metrics/service.go')
-rw-r--r-- | service/metrics/service.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/service/metrics/service.go b/service/metrics/service.go index 2c94568d..0ae86c83 100644 --- a/service/metrics/service.go +++ b/service/metrics/service.go @@ -18,11 +18,21 @@ type Service struct { mu sync.Mutex http *http.Server collectors sync.Map + registry *prometheus.Registry } // Init service. func (s *Service) Init(cfg *Config, r *rpc.Service) (bool, error) { s.cfg = cfg + s.registry = prometheus.NewRegistry() + + if err := s.registry.Register(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})); err != nil { + return false, err + } + + if err := s.registry.Register(prometheus.NewGoCollector()); err != nil { + return false, err + } if r != nil { if err := r.Register(ID, &rpcServer{s}); err != nil { @@ -40,12 +50,12 @@ func (s *Service) Enabled() bool { // Register new prometheus collector. func (s *Service) Register(c prometheus.Collector) error { - return prometheus.Register(c) + return s.registry.Register(c) } // MustRegister registers new collector or fails with panic. func (s *Service) MustRegister(c prometheus.Collector) { - if err := prometheus.Register(c); err != nil { + if err := s.registry.Register(c); err != nil { panic(err) } } @@ -59,11 +69,18 @@ func (s *Service) Serve() error { } for name, collector := range collectors { + if err := s.registry.Register(collector); err != nil { + return err + } + s.collectors.Store(name, collector) } s.mu.Lock() - s.http = &http.Server{Addr: s.cfg.Address, Handler: promhttp.Handler()} + s.http = &http.Server{Addr: s.cfg.Address, Handler: promhttp.HandlerFor( + s.registry, + promhttp.HandlerOpts{}, + )} s.mu.Unlock() return s.http.ListenAndServe() |