Open mroe1234 opened 4 years ago
Got it to work using this.
from(bucket: "my bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "something" and
r._field == "Lat" or
r._field == "Lon" or
r._field == "MCUTemp"
)
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
The above flux works for long/lat, but not if you want to use US,GB,RU 2 letter country codes.
Location Data: countries
This is my solution:
from(bucket: "pfsense")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "tail_ip_block_log")
|> filter(fn: (r) => r["_field"] == "action" or r["_field"] == "direction" or r["_field"] == "host")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> filter(fn: (r) => r.host =~ /^.*$/ and r.action == "block" and r.direction == "in")
|> group(columns: ["geoip_code"])
|> keep(columns: ["_time","geoip_code","action"])
|> count(column:"action")
|> map(fn: (r) => ({ r with _time: now() }))
credit to Grafana Issue #30290 for the last line:
|> map(fn: (r) => ({ r with _time: now() }))
This is the key to the problem of the error message: "TypeError: Cannot read property 'length' of undefined"
A transform "rename by regex" is also required: Match: action\s(.*) Replace $1
For reference this is my original fluxql query:
SELECT count("action") FROM "tail_ip_block_log" WHERE ("host" =~ /^$Host$/ AND "action" = 'block' AND "direction" = 'in') AND $timeFilter GROUP BY time(10m), "geoip_code"
Using world map-panel .3.2 and Grafana 6.7.4 my flux query:
I have also tried: |> duplicate(column: "country", as: "_field")
The output data via the influx cli looks like:
However the map remains empty.