From e7d7ce9818fad8a922a7d490b9d9eb4c3a524a94 Mon Sep 17 00:00:00 2001 From: Tony Fouchard Date: Tue, 21 Nov 2017 11:33:59 +0100 Subject: [PATCH] Fix mean calculation --- unbound_exporter.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unbound_exporter.go b/unbound_exporter.go index bc7e3ca..87a264f 100644 --- a/unbound_exporter.go +++ b/unbound_exporter.go @@ -259,6 +259,7 @@ func CollectFromReader(file io.Reader, ch chan<- prometheus.Metric) error { for _, metric := range unboundMetrics { if matches := metric.pattern.FindStringSubmatch(fields[0]); matches != nil { value, err := strconv.ParseFloat(fields[1], 64) + if err != nil { return err } @@ -276,6 +277,7 @@ func CollectFromReader(file io.Reader, ch chan<- prometheus.Metric) error { begin, _ := strconv.ParseFloat(matches[1], 64) end, _ := strconv.ParseFloat(matches[2], 64) value, err := strconv.ParseUint(fields[1], 10, 64) + if err != nil { return err } @@ -283,7 +285,7 @@ func CollectFromReader(file io.Reader, ch chan<- prometheus.Metric) error { histogramCount += value // There are no real data points to calculate the sum in the unbound stats // Therefore the mean latency times the amount of samples is calculated and summed - histogramSum += (end - begin) * float64(value) + histogramSum += (end + begin) / 2 * float64(value) } }