register std metrics once on init
Some checks failed
build / test (push) Has been cancelled
build / lint (push) Has been cancelled
codeql / analyze (go) (push) Has been cancelled

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-04-15 08:00:38 +03:00
parent 21494e0e7a
commit 1dc55cc0c9

View File

@ -288,6 +288,14 @@ func (m *prometheusMeter) Init(opts ...meter.Option) error {
for _, o := range opts { for _, o := range opts {
o(&m.opts) o(&m.opts)
} }
if m.opts.WriteProcessMetrics || m.opts.WriteFDMetrics {
pc := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})
_ = m.set.Register(pc)
gc := collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")}))
_ = m.set.Register(gc)
}
return nil return nil
} }
@ -297,13 +305,6 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
o(&options) o(&options)
} }
if options.WriteProcessMetrics || options.WriteFDMetrics {
pc := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})
_ = m.set.Register(pc)
gc := collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")}))
_ = m.set.Register(gc)
}
g, ok := m.set.(prometheus.Gatherer) g, ok := m.set.(prometheus.Gatherer)
if !ok { if !ok {
return fmt.Errorf("set type %T not prometheus.Gatherer", m.set) return fmt.Errorf("set type %T not prometheus.Gatherer", m.set)