Hello all,
I want to count records for the last 7 days for each tag and compare them with the expected number of records. In case that they are too less records I want to make a “info” alert. The problem I’m facing is, that after I make the aggregation “count” the field “_time” disappear… with that I will get a failure message that “fieldsAsCols” need the _time field. I also tried multiple workarounds but I don’t found a working one.
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/v1"
data = from(bucket: "HeatMetering")
|> range(start: -7d)
|> filter(fn: (r) => r["_measurement"] == "Consumer" or r["_measurement"] == "Creator" or r["_measurement"] == "Network")
|> filter(fn: (r) => r["_field"] == "Energy_kWh")
|> count()
|> group(columns: ["_measurement"])
// |> filter(fn: (r) => r._value < 665.0)
option task = {name: "M-Bus Check", every: 7d, offset: 0s}
check = {_check_id: "087e536c7a807000", _check_name: "M-Bus Check", _type: "threshold", tags: {}}
info = (r) => r["Energy_kWh"] < 665
messageFn = (r) => "${r._level}: one or more heat meters have communication problem"
data |> v1["fieldsAsCols"]() |> monitor["check"](data: check, messageFn: messageFn, info: info)