From 2851bffee2a69fa7c0121be1b6b7b666d74f83ae Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 14 Jul 2021 19:16:28 -0400 Subject: [PATCH] start collecting RTT and bandwidth metrics when Collect is calleed --- metrics.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/metrics.go b/metrics.go index 5dfceef..c4ea61a 100644 --- a/metrics.go +++ b/metrics.go @@ -54,8 +54,9 @@ func init() { } type aggregatingCollector struct { - mutex sync.Mutex + cronOnce sync.Once + mutex sync.Mutex highestID uint64 conns map[uint64] /* id */ *tracingConn rtts prometheus.Histogram @@ -80,7 +81,6 @@ func newAggregatingCollector() *aggregatingCollector { Buckets: prometheus.ExponentialBuckets(1, 1.5, 40), // 1s to ~12 weeks }), } - go c.cron() return c } @@ -144,6 +144,8 @@ func (c *aggregatingCollector) cron() { } func (c *aggregatingCollector) Collect(metrics chan<- prometheus.Metric) { + c.cronOnce.Do(func() { go c.cron() }) + c.mutex.Lock() defer c.mutex.Unlock()