From dfe79c136ffc362bf26142ae33be0cce00712433 Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Mon, 25 Feb 2019 16:57:20 +0100 Subject: [PATCH] added percentages to buckets --- walkerstatus.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/walkerstatus.go b/walkerstatus.go index 721f8b8..7a1a8e4 100644 --- a/walkerstatus.go +++ b/walkerstatus.go @@ -3,6 +3,7 @@ package walker import ( "fmt" "io" + "math" "sort" "time" ) @@ -71,16 +72,33 @@ func getBucketList() bucketList { } func bucketListStatus(writer io.Writer, results map[string]ScrapeResult) { + countAllRequests := float64(len(results)) + max := int64(0) + min := ^int64(0) for _, bucket := range getBucketList() { bucketI := 0 for _, result := range results { + ts := int64(result.Time.Unix()) + if ts > min { + min = ts + } + if ts < max { + max = ts + } if result.Duration > bucket.From && result.Duration < bucket.To { bucketI++ } } - fmt.Fprintln(writer, bucketI, " (", bucket.From, "=>", bucket.To, ")", bucket.Name) + fmt.Fprintln( + writer, + bucketI, + " ", + math.Round(float64(bucketI)/countAllRequests*100), + "% (", bucket.From, "=>", bucket.To, ")", + bucket.Name, + ) } - + fmt.Fprintln(writer, "=>", min, time.Unix(min, 0), max, time.Unix(max, 0)) } func (w *Walker) PrintStatus(writer io.Writer, status Status) {