Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
start collecting RTT and bandwidth metrics when Collect is calleed
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jul 14, 2021
1 parent 448dcb0 commit 2851bff
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions metrics.go
Expand Up @@ -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
Expand All @@ -80,7 +81,6 @@ func newAggregatingCollector() *aggregatingCollector {
Buckets: prometheus.ExponentialBuckets(1, 1.5, 40), // 1s to ~12 weeks
}),
}
go c.cron()
return c
}

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 2851bff

Please sign in to comment.