diff --git a/metrics/prometheus/collector.go b/metrics/prometheus/collector.go index 8187f4af02..160b72bde2 100644 --- a/metrics/prometheus/collector.go +++ b/metrics/prometheus/collector.go @@ -27,7 +27,6 @@ import ( var ( typeGaugeTpl = "# TYPE %s gauge\n" - typeCounterTpl = "# TYPE %s counter\n" typeSummaryTpl = "# TYPE %s summary\n" keyValueTpl = "%s %v\n\n" keyCounterTpl = "%s %v\n" @@ -82,11 +81,16 @@ func (c *collector) addMeter(name string, m metrics.Meter) { func (c *collector) addTimer(name string, m metrics.Timer) { pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999} ps := m.Percentiles(pv) - c.writeCounter(name, m.Count()) + + var sum float64 = 0 c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name))) for i := range pv { c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i]) + sum += ps[i] } + + c.writeSummarySum(name, fmt.Sprintf("%f", sum)) + c.writeSummaryCounter(name, len(ps)) c.buff.WriteRune('\n') } @@ -118,12 +122,6 @@ func (c *collector) writeGaugeCounter(name string, value interface{}) { c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value)) } -func (c *collector) writeCounter(name string, value interface{}) { - name = mutateKey(name + "_count") - c.buff.WriteString(fmt.Sprintf(typeCounterTpl, name)) - c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value)) -} - func (c *collector) writeSummaryCounter(name string, value interface{}) { name = mutateKey(name + "_count") c.buff.WriteString(fmt.Sprintf(keyCounterTpl, name, value)) diff --git a/metrics/prometheus/collector_test.go b/metrics/prometheus/collector_test.go index b1cc2aaf89..979fdbc6a3 100644 --- a/metrics/prometheus/collector_test.go +++ b/metrics/prometheus/collector_test.go @@ -80,9 +80,6 @@ test_histogram_count 6 # TYPE test_meter gauge test_meter 9999999 -# TYPE test_timer_count counter -test_timer_count 6 - # TYPE test_timer summary test_timer {quantile="0.5"} 2.25e+07 test_timer {quantile="0.75"} 4.8e+07 @@ -90,6 +87,8 @@ test_timer {quantile="0.95"} 1.2e+08 test_timer {quantile="0.99"} 1.2e+08 test_timer {quantile="0.999"} 1.2e+08 test_timer {quantile="0.9999"} 1.2e+08 +test_timer_sum 550500000.000000 +test_timer_count 6 # TYPE test_resetting_timer summary test_resetting_timer {quantile="0.50"} 12000000