check_nodes: tune query

This commit is contained in:
Joerg Lehmann 2021-04-17 17:49:53 +02:00
parent dac9b4ac2f
commit ac79afe97a
1 changed files with 6 additions and 5 deletions

View File

@ -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])
}