fixup golang std metrics
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
4cd610a474
commit
1862ee5380
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -280,8 +281,10 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...options.Option) error {
|
||||
}
|
||||
|
||||
if options.WriteProcessMetrics || options.WriteFDMetrics {
|
||||
c := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})
|
||||
_ = m.set.Register(c)
|
||||
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)
|
||||
|
@ -11,6 +11,18 @@ import (
|
||||
"go.unistack.org/micro/v4/meter/wrapper"
|
||||
)
|
||||
|
||||
func TestStd(t *testing.T) {
|
||||
m := NewMeter(meter.WriteProcessMetrics(true), meter.WriteFDMetrics(true))
|
||||
if err := m.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
_ = m.Write(buf)
|
||||
if !bytes.Contains(buf.Bytes(), []byte(`go_goroutine`)) {
|
||||
t.Fatalf("invalid metrics output: %s", buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildName(t *testing.T) {
|
||||
m := NewMeter()
|
||||
check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`
|
||||
|
Loading…
Reference in New Issue
Block a user