record quantiles as well

This commit is contained in:
Oliver 2015-05-04 19:20:11 -04:00
parent ff586eaac1
commit 21b132f5a2
2 changed files with 18 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package prometheus
import (
"runtime"
"runtime/debug"
"time"
)
type goCollector struct {
@ -37,7 +38,13 @@ func (c *goCollector) Collect(ch chan<- Metric) {
ch <- c.goroutines
var stats debug.GCStats
stats.PauseQuantiles = make([]time.Duration, 5)
debug.ReadGCStats(&stats)
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), nil)
quantiles := make(map[float64]float64)
for idx, pq := range stats.PauseQuantiles[1:] {
quantiles[float64(idx+1)/float64(len(stats.PauseQuantiles)-1)] = pq.Seconds()
}
quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles)
}

View File

@ -1,7 +1,7 @@
package prometheus
import (
"runtime/debug"
"runtime"
"testing"
"time"
@ -72,7 +72,7 @@ func TestGCCollector(t *testing.T) {
go func() {
c.Collect(ch)
// force GC
debug.FreeOSMemory()
runtime.GC()
<-waitc
c.Collect(ch)
}()
@ -89,6 +89,14 @@ func TestGCCollector(t *testing.T) {
continue
}
if len(pb.GetSummary().Quantile) != 5 {
t.Errorf("expected 4 buckets, got %d", len(pb.GetSummary().Quantile))
}
for idx, want := range []float64{0.0, 0.25, 0.5, 0.75, 1.0} {
if *pb.GetSummary().Quantile[idx].Quantile != want {
t.Errorf("bucket #%d is off, got %f, want %f", idx, *pb.GetSummary().Quantile[idx].Quantile, want)
}
}
if first {
first = false
oldGC = *pb.GetSummary().SampleCount