func (this *ConsumerMetrics) WriteJSON(reportingInterval time.Duration, writer io.Writer) {
	tick := time.Tick(reportingInterval)
	stop := make(chan struct{})

	inLock(&this.metricLock, func() {
		this.reportingStopChannels = append(this.reportingStopChannels, stop)
	})

	for {
		select {
		case <-tick:
			metrics.WriteJSONOnce(this.registry, writer)
		case <-stop:
			return
		}
	}
}
Exemple #2
0
// ToJSON returns a representation of all the metrics in JSON format.
func (m *MetricTags) ToJSON() []byte {
	buf := bytes.NewBuffer(nil)
	metrics.WriteJSONOnce(m.registry, buf)
	return buf.Bytes()
}