forked from mirror/client_golang
don't reuse memstats
This commit is contained in:
parent
8a031ee219
commit
6c7a1db6bf
|
@ -11,8 +11,6 @@ type goCollector struct {
|
||||||
goroutines Gauge
|
goroutines Gauge
|
||||||
gcDesc *Desc
|
gcDesc *Desc
|
||||||
|
|
||||||
// memstats object to reuse
|
|
||||||
ms *runtime.MemStats
|
|
||||||
// metrics to describe and collect
|
// metrics to describe and collect
|
||||||
metrics memStatsMetrics
|
metrics memStatsMetrics
|
||||||
}
|
}
|
||||||
|
@ -21,7 +19,6 @@ type goCollector struct {
|
||||||
// go process.
|
// go process.
|
||||||
func NewGoCollector() *goCollector {
|
func NewGoCollector() *goCollector {
|
||||||
return &goCollector{
|
return &goCollector{
|
||||||
ms: new(runtime.MemStats),
|
|
||||||
goroutines: NewGauge(GaugeOpts{
|
goroutines: NewGauge(GaugeOpts{
|
||||||
Namespace: "go",
|
Namespace: "go",
|
||||||
Name: "goroutines",
|
Name: "goroutines",
|
||||||
|
@ -267,13 +264,14 @@ func (c *goCollector) Collect(ch chan<- Metric) {
|
||||||
quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
|
quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
|
||||||
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles)
|
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles)
|
||||||
|
|
||||||
runtime.ReadMemStats(c.ms)
|
ms := &runtime.MemStats{}
|
||||||
|
runtime.ReadMemStats(ms)
|
||||||
for _, i := range c.metrics {
|
for _, i := range c.metrics {
|
||||||
ch <- MustNewConstMetric(i.desc, i.valType, i.eval(c.ms))
|
ch <- MustNewConstMetric(i.desc, i.valType, i.eval(ms))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// memStatsMetrics provide description, value, and value type for memstat metrics
|
// memStatsMetrics provide description, value, and value type for memstat metrics.
|
||||||
type memStatsMetrics []struct {
|
type memStatsMetrics []struct {
|
||||||
desc *Desc
|
desc *Desc
|
||||||
eval func(*runtime.MemStats) float64
|
eval func(*runtime.MemStats) float64
|
||||||
|
|
Loading…
Reference in New Issue