fixup golang std metrics
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
e02f291db2
commit
439d5cf125
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -279,8 +280,10 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if options.WriteProcessMetrics || options.WriteFDMetrics {
|
if options.WriteProcessMetrics || options.WriteFDMetrics {
|
||||||
c := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})
|
pc := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})
|
||||||
_ = m.set.Register(c)
|
_ = 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)
|
||||||
|
@ -11,6 +11,18 @@ import (
|
|||||||
"go.unistack.org/micro/v3/meter/wrapper"
|
"go.unistack.org/micro/v3/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) {
|
func TestBuildName(t *testing.T) {
|
||||||
m := NewMeter()
|
m := NewMeter()
|
||||||
check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`
|
check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`
|
||||||
|
Loading…
Reference in New Issue
Block a user