From ac79afe97a3f4246eef529f272f85f027ee80ebd Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Sat, 17 Apr 2021 17:49:53 +0200 Subject: [PATCH] check_nodes: tune query --- check_nodes/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/check_nodes/main.go b/check_nodes/main.go index a267823..d37c9ec 100644 --- a/check_nodes/main.go +++ b/check_nodes/main.go @@ -290,9 +290,8 @@ func getLastMetrics(deveui string) OneMetric { data := []byte(fmt.Sprintf(`from(bucket:"wobischbucket") |> range(start:-5d) |> filter(fn: (r) => r._measurement == "measurement" and r.deveui == "%s") - |> filter(fn: (r) => r._field == "lon" or r._field == "lat" or r._field == "vbat" or r._field == "fw") - |> last(column: "_time") - |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")`, deveui)) + |> filter(fn: (r) => r._field == "vbat") + |> last(column: "_time")`, deveui)) req, err := http.NewRequest("POST", url, bytes.NewBuffer(data)) if err != nil { @@ -329,7 +328,8 @@ func getLastMetrics(deveui string) OneMetric { location, err := time.LoadLocation("Europe/Zurich") for scanner.Scan() { s := strings.Split(scanner.Text(), ",") - if (len(s) >= 9) && !(strings.HasPrefix(s[3], "_")) { + //fmt.Printf("s: %q\n", s) + if (len(s) >= 7) && !(strings.HasPrefix(s[3], "_")) { t, err := time.Parse(time.RFC3339, s[5]) if err != nil { fmt.Printf("error converting time: %s\n", s[5]) @@ -337,7 +337,8 @@ func getLastMetrics(deveui string) OneMetric { } res.Timestamp = t.In(location).Format("02.01.2006 15:04") - res.BatteryPercent = strconv.Itoa(vbat2percent(s[8])) + res.BatteryPercent = strconv.Itoa(vbat2percent(s[6])) + fmt.Printf("vbat: %s\n", s[6]) }