unembed memstats collector
This commit is contained in:
parent
c945ed62c1
commit
8a031ee219
|
@ -11,13 +11,17 @@ type goCollector struct {
|
|||
goroutines Gauge
|
||||
gcDesc *Desc
|
||||
|
||||
memstats *memStatCollector
|
||||
// memstats object to reuse
|
||||
ms *runtime.MemStats
|
||||
// metrics to describe and collect
|
||||
metrics memStatsMetrics
|
||||
}
|
||||
|
||||
// NewGoCollector returns a collector which exports metrics about the current
|
||||
// go process.
|
||||
func NewGoCollector() *goCollector {
|
||||
return &goCollector{
|
||||
ms: new(runtime.MemStats),
|
||||
goroutines: NewGauge(GaugeOpts{
|
||||
Namespace: "go",
|
||||
Name: "goroutines",
|
||||
|
@ -27,8 +31,6 @@ func NewGoCollector() *goCollector {
|
|||
"go_gc_duration_seconds",
|
||||
"A summary of the GC invocation durations.",
|
||||
nil, nil),
|
||||
memstats: &memStatCollector{
|
||||
ms: new(runtime.MemStats),
|
||||
metrics: memStatsMetrics{
|
||||
{
|
||||
desc: NewDesc(
|
||||
|
@ -232,7 +234,6 @@ func NewGoCollector() *goCollector {
|
|||
valType: CounterValue,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,7 +246,9 @@ func (c *goCollector) Describe(ch chan<- *Desc) {
|
|||
ch <- c.goroutines.Desc()
|
||||
ch <- c.gcDesc
|
||||
|
||||
c.memstats.Describe(ch)
|
||||
for _, i := range c.metrics {
|
||||
ch <- i.desc
|
||||
}
|
||||
}
|
||||
|
||||
// Collect returns the current state of all metrics of the collector.
|
||||
|
@ -264,32 +267,15 @@ func (c *goCollector) Collect(ch chan<- Metric) {
|
|||
quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
|
||||
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles)
|
||||
|
||||
c.memstats.Collect(ch)
|
||||
}
|
||||
|
||||
// metrics that provide description, value, and value type for memstat metrics
|
||||
type memStatsMetrics []struct {
|
||||
desc *Desc
|
||||
eval func(*runtime.MemStats) float64
|
||||
valType ValueType
|
||||
}
|
||||
|
||||
type memStatCollector struct {
|
||||
// memstats object to reuse
|
||||
ms *runtime.MemStats
|
||||
// metrics to describe and collect
|
||||
metrics memStatsMetrics
|
||||
}
|
||||
|
||||
func (c *memStatCollector) Describe(ch chan<- *Desc) {
|
||||
for _, i := range c.metrics {
|
||||
ch <- i.desc
|
||||
}
|
||||
}
|
||||
|
||||
func (c *memStatCollector) Collect(ch chan<- Metric) {
|
||||
runtime.ReadMemStats(c.ms)
|
||||
for _, i := range c.metrics {
|
||||
ch <- MustNewConstMetric(i.desc, i.valType, i.eval(c.ms))
|
||||
}
|
||||
}
|
||||
|
||||
// memStatsMetrics provide description, value, and value type for memstat metrics
|
||||
type memStatsMetrics []struct {
|
||||
desc *Desc
|
||||
eval func(*runtime.MemStats) float64
|
||||
valType ValueType
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue