func collectGaugeValue(gauge stat.Collector) float64 {
	collectChan := make(chan stat.Metric)
	var value float64
	go gauge.Collect(collectChan)
	select {
	case metric := <-collectChan:
		metricDto := &dto.Metric{}
		metric.Write(metricDto)
		value = metricDto.GetGauge().GetValue()
	}
	close(collectChan)
	return value
}
Пример #2
0
func (r *reporter) report() {
	var collector prometheus.Collector = mDuration // TODO make collector argument?

	metrics := make(chan prometheus.Metric)
	done := make(chan struct{})
	go func() {
	Next:
		for m := range metrics {
			var metric dto.Metric
			err := m.Write(&metric)
			if err != nil {
				r.logger.Fatal(err)
			}

			for _, l := range metric.Label {
				if l.GetName() != "test" {
					continue
				}
				name := r.name.Load().(string)
				if name != "" && l.GetValue() != name {
					continue Next
				}
				r.logger.Printf("%s stats:", l.GetValue())
			}
			r.logger.Printf("\t%d observations, sum %s",
				metric.Summary.GetSampleCount(), time.Duration(metric.Summary.GetSampleSum()*float64(time.Second)))
			for _, q := range metric.Summary.Quantile {
				r.logger.Printf("\t%.2fφ: %s",
					q.GetQuantile(), time.Duration(q.GetValue()*float64(time.Second)))
			}
		}
		close(done)
	}()

	collector.Collect(metrics)
	close(metrics)
	<-done
}