Data for World Map Panel Plugin in Grafana:
Approach 1:
Using the InfluxDB data:
- Here, the data is pulled from the database(InfluxDB) from a single measurement(table).
Schema of the hdb7 table is:
Time | DS_ID | from | graphStatement | latitude | longitude | to | totalPower | value |
---|
The above is the data that is pushed to the measurement(hdb7) of the InfluxDB database. Here, the hdb7 table’s graphStatement field values will be shown on the world map.
Query:
SELECT * from "hdb7" GROUP BY * ORDER BY DESC LIMIT 4
col1 | col2 |
---|---|
Location Data | table |
Aggregation | current |
Map Data Options
Field Mapping
col1 | col2 |
---|---|
Table Query Format | coordinates |
Location Name Field | graphStatement |
Metric Field | value |
Latitude Field | latitude |
Longitude Field | longitude |
Field Mapping
DrawBack:
1.
The requirement specifically mentions having 2 tables like shown below.
JOIN statements are not supported in InfluxDB.
Table1
DS_ID, Lat, Long
Table2
DS_ID, Sum(pump),sum(light),..total value
Table1:
DS_ID | latitude | longitude | value | time |
---|
Table2:
DS_ID | graphStatement | totalPower | value | time |
---|
The graphStatement covers the fields sum(boosterPump), sum(lighting), sum(lift) which are to be displayed on the map.
“JOIN is no longer a concept in 0.9. Series sharing a measurement can be queried together simply by omitting the differentiating tags from the WHERE clause.”
Link:
https://github.com/influxdata/influxdb/issues/624
However, there is one alternative called transformations in Grafana that can be used to join 2 tables of same datasource/mixed datasource as shown below.
Here, the data for Table1 (DS_ID, Lat, Long) will be queried from MySQL database. The data for Table2 (DS_ID, Sum(pump),sum(light),..total value) will be queried from InfluxDB database.
Implementation:
-
We can implement the above by choosing the datasource as Mixed.
The query 1 will be:
SELECT * from hdb10The query 2 will be:
SELECT * from hdb9The transform we are going to apply is :
Outer join: DS_ID
All the pictures are shown below:
When we change the metric field to Total(field from hdb10) we get the value on the map as shown below:
Approach 2:
Using the MYSQL data:
- Here, the data is pulled from the database(MySQL) from a 2 tables.
DB Connection in Grafana(Add Data sources MySQL):
Host localhost:3306
Database database_name
SELECT CONCAT( "-") AS Conca, worldmap_latlng_a.lat, worldmap_latlng_a.lng, worldmap_latlng_a.DS_ID, total_power.Total
FROM total_power
INNER JOIN worldmap_latlng_a
ON worldmap_latlng_a.DS_ID = total_power.DS_I
The data we get is:
Conca lat lng DS_ID Total
- 1.4 104 0 14988
Here, we are getting both the data of the table1(worldmap_latlng_a) and the table2(total_power) from the join query executed above.
Top comments (0)