10 "github.com/go-kit/kit/metrics/generic"
13 // SumLines expects a regex whose first capture group can be parsed as a
14 // float64. It will dump the WriterTo and parse each line, expecting to find a
15 // match. It returns the sum of all captured floats.
16 func SumLines(w io.WriterTo, regex string) func() float64 {
17 return func() float64 {
18 sum, _ := stats(w, regex, nil)
23 // LastLine expects a regex whose first capture group can be parsed as a
24 // float64. It will dump the WriterTo and parse each line, expecting to find a
25 // match. It returns the final captured float.
26 func LastLine(w io.WriterTo, regex string) func() float64 {
27 return func() float64 {
28 _, final := stats(w, regex, nil)
33 // Quantiles expects a regex whose first capture group can be parsed as a
34 // float64. It will dump the WriterTo and parse each line, expecting to find a
35 // match. It observes all captured floats into a generic.Histogram with the
36 // given number of buckets, and returns the 50th, 90th, 95th, and 99th quantiles
37 // from that histogram.
38 func Quantiles(w io.WriterTo, regex string, buckets int) func() (float64, float64, float64, float64) {
39 return func() (float64, float64, float64, float64) {
40 h := generic.NewHistogram("quantile-test", buckets)
42 return h.Quantile(0.50), h.Quantile(0.90), h.Quantile(0.95), h.Quantile(0.99)
46 func stats(w io.WriterTo, regex string, h *generic.Histogram) (sum, final float64) {
47 re := regexp.MustCompile(regex)
48 buf := &bytes.Buffer{}
50 //fmt.Fprintf(os.Stderr, "%s\n", buf.String())
51 s := bufio.NewScanner(buf)
53 match := re.FindStringSubmatch(s.Text())
54 f, err := strconv.ParseFloat(match[1], 64)