From 8c09687e8602deb607e026eadeb1527a6c9989c2 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Tue, 4 Oct 2016 15:00:54 +0200 Subject: [PATCH] fix bugs rrd importer -> clients are no nodes :) --- rrd/rrd.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rrd/rrd.go b/rrd/rrd.go index 160166f..725f302 100644 --- a/rrd/rrd.go +++ b/rrd/rrd.go @@ -13,12 +13,14 @@ import ( var linePattern = regexp.MustCompile("^ ([^<]+)([^<]+)") +// Dataset a timestemp with values (node and clients) type Dataset struct { Time time.Time Nodes float64 Clients float64 } +// Read a rrdfile and return a chanel of datasets func Read(rrdFile string) chan Dataset { out := make(chan Dataset) cmd := exec.Command("rrdtool", "dump", rrdFile) @@ -48,10 +50,10 @@ func Read(rrdFile string) chan Dataset { found = strings.Contains(str, "") continue } - if matches := linePattern.FindStringSubmatch(str); matches != nil && matches[2] != "NaN" { + if matches := linePattern.FindStringSubmatch(str); matches != nil && matches[2] != "NaN" && matches[3] != "NaN" { seconds, _ := strconv.Atoi(matches[1]) nodes, _ := strconv.ParseFloat(matches[2], 64) - clients, _ := strconv.ParseFloat(matches[2], 64) + clients, _ := strconv.ParseFloat(matches[3], 64) out <- Dataset{ Time: time.Unix(int64(seconds), 0),