Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
21494e0e7a | |||
0975e8fb4d | |||
8dfa97b54f | |||
439d5cf125 |
218
prometheus.go
218
prometheus.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -19,32 +20,32 @@ var _ meter.Meter = &prometheusMeter{}
|
|||||||
type prometheusMeter struct {
|
type prometheusMeter struct {
|
||||||
opts meter.Options
|
opts meter.Options
|
||||||
set prometheus.Registerer
|
set prometheus.Registerer
|
||||||
counter map[string]*counters
|
counter *sync.Map
|
||||||
floatCounter map[string]*floatCounters
|
floatCounter *sync.Map
|
||||||
gauge map[string]*gauges
|
gauge *sync.Map
|
||||||
histogram map[string]*histograms
|
histogram *sync.Map
|
||||||
summary map[string]*summaries
|
summary *sync.Map
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type counters struct {
|
type counters struct {
|
||||||
cs map[uint64]*prometheusCounter
|
cs *sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type gauges struct {
|
type gauges struct {
|
||||||
cs map[uint64]*prometheusGauge
|
cs *sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type histograms struct {
|
type histograms struct {
|
||||||
cs map[uint64]*prometheusHistogram
|
cs *sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type summaries struct {
|
type summaries struct {
|
||||||
cs map[uint64]*prometheusSummary
|
cs *sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type floatCounters struct {
|
type floatCounters struct {
|
||||||
cs map[uint64]*prometheusFloatCounter
|
cs *sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFloat64(v float64) *float64 {
|
func newFloat64(v float64) *float64 {
|
||||||
@@ -61,11 +62,11 @@ func NewMeter(opts ...meter.Option) *prometheusMeter {
|
|||||||
return &prometheusMeter{
|
return &prometheusMeter{
|
||||||
set: prometheus.NewRegistry(), // prometheus.DefaultRegisterer,
|
set: prometheus.NewRegistry(), // prometheus.DefaultRegisterer,
|
||||||
opts: meter.NewOptions(opts...),
|
opts: meter.NewOptions(opts...),
|
||||||
counter: make(map[string]*counters),
|
counter: &sync.Map{},
|
||||||
floatCounter: make(map[string]*floatCounters),
|
floatCounter: &sync.Map{},
|
||||||
gauge: make(map[string]*gauges),
|
gauge: &sync.Map{},
|
||||||
histogram: make(map[string]*histograms),
|
histogram: &sync.Map{},
|
||||||
summary: make(map[string]*summaries),
|
summary: &sync.Map{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,22 +124,25 @@ func (m *prometheusMeter) Counter(name string, labels ...string) meter.Counter {
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
nm := m.buildName(name)
|
nm := m.buildName(name)
|
||||||
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
labels = m.buildLabels(append(m.opts.Labels, labels...)...) // TODO: Read prometheus.go:128
|
||||||
cd, ok := m.counter[nm]
|
vcd, ok := m.counter.Load(nm)
|
||||||
h := newHash(labels)
|
h := newHash(labels)
|
||||||
if !ok {
|
if !ok {
|
||||||
cd = &counters{cs: make(map[uint64]*prometheusCounter)}
|
cd := &counters{cs: &sync.Map{}}
|
||||||
c := &prometheusCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
c := &prometheusCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.counter[nm] = cd
|
m.counter.Store(nm, cd)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
c, ok := cd.cs[h]
|
cd := vcd.(*counters)
|
||||||
|
vc, ok := cd.cs.Load(h)
|
||||||
if !ok {
|
if !ok {
|
||||||
c = &prometheusCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
c := &prometheusCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.counter[nm] = cd
|
m.counter.Store(nm, cd)
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
c := vc.(*prometheusCounter)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,21 +151,24 @@ func (m *prometheusMeter) FloatCounter(name string, labels ...string) meter.Floa
|
|||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
nm := m.buildName(name)
|
nm := m.buildName(name)
|
||||||
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
||||||
cd, ok := m.floatCounter[nm]
|
vcd, ok := m.floatCounter.Load(nm)
|
||||||
h := newHash(labels)
|
h := newHash(labels)
|
||||||
if !ok {
|
if !ok {
|
||||||
cd = &floatCounters{cs: make(map[uint64]*prometheusFloatCounter)}
|
cd := &floatCounters{cs: &sync.Map{}}
|
||||||
c := &prometheusFloatCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
c := &prometheusFloatCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.floatCounter[nm] = cd
|
m.floatCounter.Store(nm, cd)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
c, ok := cd.cs[h]
|
cd := vcd.(*floatCounters)
|
||||||
|
vc, ok := cd.cs.Load(h)
|
||||||
if !ok {
|
if !ok {
|
||||||
c = &prometheusFloatCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
c := &prometheusFloatCounter{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.floatCounter[nm] = cd
|
m.floatCounter.Store(nm, cd)
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
c := vc.(*prometheusFloatCounter)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,21 +177,24 @@ func (m *prometheusMeter) Gauge(name string, fn func() float64, labels ...string
|
|||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
nm := m.buildName(name)
|
nm := m.buildName(name)
|
||||||
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
||||||
cd, ok := m.gauge[nm]
|
vcd, ok := m.gauge.Load(nm)
|
||||||
h := newHash(labels)
|
h := newHash(labels)
|
||||||
if !ok {
|
if !ok {
|
||||||
cd = &gauges{cs: make(map[uint64]*prometheusGauge)}
|
cd := &gauges{cs: &sync.Map{}}
|
||||||
c := &prometheusGauge{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
c := &prometheusGauge{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.gauge[nm] = cd
|
m.gauge.Store(nm, cd)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
c, ok := cd.cs[h]
|
cd := vcd.(*gauges)
|
||||||
|
vc, ok := cd.cs.Load(h)
|
||||||
if !ok {
|
if !ok {
|
||||||
c = &prometheusGauge{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
c := &prometheusGauge{c: prometheus.NewGauge(prometheus.GaugeOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.gauge[nm] = cd
|
m.gauge.Store(nm, cd)
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
c := vc.(*prometheusGauge)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,21 +203,24 @@ func (m *prometheusMeter) Histogram(name string, labels ...string) meter.Histogr
|
|||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
nm := m.buildName(name)
|
nm := m.buildName(name)
|
||||||
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
||||||
cd, ok := m.histogram[nm]
|
vcd, ok := m.histogram.Load(nm)
|
||||||
h := newHash(labels)
|
h := newHash(labels)
|
||||||
if !ok {
|
if !ok {
|
||||||
cd = &histograms{cs: make(map[uint64]*prometheusHistogram)}
|
cd := &histograms{cs: &sync.Map{}}
|
||||||
c := &prometheusHistogram{c: prometheus.NewHistogram(prometheus.HistogramOpts{Name: nm}), labels: labels}
|
c := &prometheusHistogram{c: prometheus.NewHistogram(prometheus.HistogramOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.histogram[nm] = cd
|
m.histogram.Store(nm, cd)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
c, ok := cd.cs[h]
|
cd := vcd.(*histograms)
|
||||||
|
vc, ok := cd.cs.Load(h)
|
||||||
if !ok {
|
if !ok {
|
||||||
c = &prometheusHistogram{c: prometheus.NewHistogram(prometheus.HistogramOpts{Name: nm}), labels: labels}
|
c := &prometheusHistogram{c: prometheus.NewHistogram(prometheus.HistogramOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.histogram[nm] = cd
|
m.histogram.Store(nm, cd)
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
c := vc.(*prometheusHistogram)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,21 +229,24 @@ func (m *prometheusMeter) Summary(name string, labels ...string) meter.Summary {
|
|||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
nm := m.buildName(name)
|
nm := m.buildName(name)
|
||||||
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
||||||
cd, ok := m.summary[nm]
|
vcd, ok := m.summary.Load(nm)
|
||||||
h := newHash(labels)
|
h := newHash(labels)
|
||||||
if !ok {
|
if !ok {
|
||||||
cd = &summaries{cs: make(map[uint64]*prometheusSummary)}
|
cd := &summaries{cs: &sync.Map{}}
|
||||||
c := &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{Name: nm}), labels: labels}
|
c := &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.summary[nm] = cd
|
m.summary.Store(nm, cd)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
c, ok := cd.cs[h]
|
cd := vcd.(*summaries)
|
||||||
|
vc, ok := cd.cs.Load(h)
|
||||||
if !ok {
|
if !ok {
|
||||||
c = &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{Name: nm}), labels: labels}
|
c := &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{Name: nm}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.summary[nm] = cd
|
m.summary.Store(nm, cd)
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
c := vc.(*prometheusSummary)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,29 +255,32 @@ func (m *prometheusMeter) SummaryExt(name string, window time.Duration, quantile
|
|||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
nm := m.buildName(name)
|
nm := m.buildName(name)
|
||||||
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
labels = m.buildLabels(append(m.opts.Labels, labels...)...)
|
||||||
cd, ok := m.summary[nm]
|
vcd, ok := m.summary.Load(nm)
|
||||||
h := newHash(labels)
|
h := newHash(labels)
|
||||||
if !ok {
|
if !ok {
|
||||||
cd = &summaries{cs: make(map[uint64]*prometheusSummary)}
|
cd := &summaries{cs: &sync.Map{}}
|
||||||
c := &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{
|
c := &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{
|
||||||
Name: nm,
|
Name: nm,
|
||||||
MaxAge: window,
|
MaxAge: window,
|
||||||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||||
}), labels: labels}
|
}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.summary[nm] = cd
|
m.summary.Store(nm, cd)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
c, ok := cd.cs[h]
|
cd := vcd.(*summaries)
|
||||||
|
vc, ok := cd.cs.Load(h)
|
||||||
if !ok {
|
if !ok {
|
||||||
c = &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{
|
c := &prometheusSummary{c: prometheus.NewSummary(prometheus.SummaryOpts{
|
||||||
Name: nm,
|
Name: nm,
|
||||||
MaxAge: window,
|
MaxAge: window,
|
||||||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||||
}), labels: labels}
|
}), labels: labels}
|
||||||
cd.cs[h] = c
|
cd.cs.Store(h, c)
|
||||||
m.summary[nm] = cd
|
m.summary.Store(nm, cd)
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
c := vc.(*prometheusSummary)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,8 +298,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)
|
||||||
@@ -295,80 +316,95 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
|
|||||||
|
|
||||||
enc := expfmt.NewEncoder(w, expfmt.NewFormat(expfmt.TypeTextPlain))
|
enc := expfmt.NewEncoder(w, expfmt.NewFormat(expfmt.TypeTextPlain))
|
||||||
|
|
||||||
for name, metrics := range m.counter {
|
m.counter.Range(func(k, v any) bool {
|
||||||
|
name := k.(string)
|
||||||
mf := &dto.MetricFamily{
|
mf := &dto.MetricFamily{
|
||||||
Name: newString(name),
|
Name: newString(name),
|
||||||
Type: dto.MetricType_GAUGE.Enum(),
|
Type: dto.MetricType_GAUGE.Enum(),
|
||||||
Metric: make([]*dto.Metric, 0, len(metrics.cs)),
|
|
||||||
}
|
}
|
||||||
for _, c := range metrics.cs {
|
v.(*counters).cs.Range(func(_, nv any) bool {
|
||||||
|
c := nv.(*prometheusCounter)
|
||||||
m := &dto.Metric{}
|
m := &dto.Metric{}
|
||||||
_ = c.c.Write(m)
|
_ = c.c.Write(m)
|
||||||
fillMetric(m, c.labels)
|
fillMetric(m, c.labels)
|
||||||
mf.Metric = append(mf.Metric, m)
|
mf.Metric = append(mf.Metric, m)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
mfs = append(mfs, mf)
|
mfs = append(mfs, mf)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
for name, metrics := range m.gauge {
|
m.gauge.Range(func(k, v any) bool {
|
||||||
|
name := k.(string)
|
||||||
mf := &dto.MetricFamily{
|
mf := &dto.MetricFamily{
|
||||||
Name: newString(name),
|
Name: newString(name),
|
||||||
Type: dto.MetricType_GAUGE.Enum(),
|
Type: dto.MetricType_GAUGE.Enum(),
|
||||||
Metric: make([]*dto.Metric, 0, len(metrics.cs)),
|
|
||||||
}
|
}
|
||||||
for _, c := range metrics.cs {
|
v.(*gauges).cs.Range(func(_, nv any) bool {
|
||||||
|
c := nv.(*prometheusGauge)
|
||||||
m := &dto.Metric{}
|
m := &dto.Metric{}
|
||||||
_ = c.c.Write(m)
|
_ = c.c.Write(m)
|
||||||
fillMetric(m, c.labels)
|
fillMetric(m, c.labels)
|
||||||
mf.Metric = append(mf.Metric, m)
|
mf.Metric = append(mf.Metric, m)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
mfs = append(mfs, mf)
|
mfs = append(mfs, mf)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
for name, metrics := range m.floatCounter {
|
m.floatCounter.Range(func(k, v any) bool {
|
||||||
|
name := k.(string)
|
||||||
mf := &dto.MetricFamily{
|
mf := &dto.MetricFamily{
|
||||||
Name: newString(name),
|
Name: newString(name),
|
||||||
Type: dto.MetricType_GAUGE.Enum(),
|
Type: dto.MetricType_GAUGE.Enum(),
|
||||||
Metric: make([]*dto.Metric, 0, len(metrics.cs)),
|
|
||||||
}
|
}
|
||||||
for _, c := range metrics.cs {
|
v.(*floatCounters).cs.Range(func(_, nv any) bool {
|
||||||
|
c := nv.(*prometheusFloatCounter)
|
||||||
m := &dto.Metric{}
|
m := &dto.Metric{}
|
||||||
_ = c.c.Write(m)
|
_ = c.c.Write(m)
|
||||||
fillMetric(m, c.labels)
|
fillMetric(m, c.labels)
|
||||||
mf.Metric = append(mf.Metric, m)
|
mf.Metric = append(mf.Metric, m)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
mfs = append(mfs, mf)
|
mfs = append(mfs, mf)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
for name, metrics := range m.histogram {
|
m.histogram.Range(func(k, v any) bool {
|
||||||
|
name := k.(string)
|
||||||
mf := &dto.MetricFamily{
|
mf := &dto.MetricFamily{
|
||||||
Name: newString(name),
|
Name: newString(name),
|
||||||
Type: dto.MetricType_HISTOGRAM.Enum(),
|
Type: dto.MetricType_HISTOGRAM.Enum(),
|
||||||
Metric: make([]*dto.Metric, 0, len(metrics.cs)),
|
|
||||||
}
|
}
|
||||||
for _, c := range metrics.cs {
|
v.(*histograms).cs.Range(func(_, nv any) bool {
|
||||||
|
c := nv.(*prometheusHistogram)
|
||||||
m := &dto.Metric{}
|
m := &dto.Metric{}
|
||||||
_ = c.c.Write(m)
|
_ = c.c.Write(m)
|
||||||
fillMetric(m, c.labels)
|
fillMetric(m, c.labels)
|
||||||
mf.Metric = append(mf.Metric, m)
|
mf.Metric = append(mf.Metric, m)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
mfs = append(mfs, mf)
|
mfs = append(mfs, mf)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
for name, metrics := range m.summary {
|
m.summary.Range(func(k, v any) bool {
|
||||||
|
name := k.(string)
|
||||||
mf := &dto.MetricFamily{
|
mf := &dto.MetricFamily{
|
||||||
Name: newString(name),
|
Name: newString(name),
|
||||||
Type: dto.MetricType_SUMMARY.Enum(),
|
Type: dto.MetricType_SUMMARY.Enum(),
|
||||||
Metric: make([]*dto.Metric, 0, len(metrics.cs)),
|
|
||||||
}
|
}
|
||||||
for _, c := range metrics.cs {
|
v.(*summaries).cs.Range(func(_, nv any) bool {
|
||||||
|
c := nv.(*prometheusSummary)
|
||||||
m := &dto.Metric{}
|
m := &dto.Metric{}
|
||||||
_ = c.c.Write(m)
|
_ = c.c.Write(m)
|
||||||
fillMetric(m, c.labels)
|
fillMetric(m, c.labels)
|
||||||
mf.Metric = append(mf.Metric, m)
|
mf.Metric = append(mf.Metric, m)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
mfs = append(mfs, mf)
|
mfs = append(mfs, mf)
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
for _, mf := range mfs {
|
for _, mf := range mfs {
|
||||||
_ = enc.Encode(mf)
|
_ = enc.Encode(mf)
|
||||||
|
@@ -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"}`
|
||||||
|
Reference in New Issue
Block a user