DEV Community

Krishna Kurtakoti
Krishna Kurtakoti

Posted on

Data for World Map Panel Plugin in Grafana from MySQL

Data for World Map Panel Plugin in Grafana:

Approach 1:

Using the InfluxDB data:

  1. 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

Screenshot from 2021-01-07 13-34-28

a1.png

a2.png

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

Screenshot from 2021-01-05 16-43-23p1d1

Screenshot from 2021-01-05 16-44-00p1d2

Field Mapping

Screenshot from 2021-01-05 16-44-09p1d3

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:

  1. We can implement the above by choosing the datasource as Mixed.
    The query 1 will be:
    SELECT * from hdb10

    The query 2 will be:
    SELECT * from hdb9

    The transform we are going to apply is :
    Outer join: DS_ID

All the pictures are shown below:

Screenshot from 2021-01-08 15-07-09p2d1

Screenshot from 2021-01-08 15-07-28p2d2

When we change the metric field to Total(field from hdb10) we get the value on the map as shown below:

Screenshot from 2021-01-08 15-15-02p2d3

Approach 2:

Using the MYSQL data:

  1. 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
Screenshot from 2021-01-05 17-35-47

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

Screenshot from 2021-01-05 17-09-46p1d4

Screenshot from 2021-01-05 17-11-27p1d5

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.

Screenshot from 2021-01-05 17-11-54p1d6

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DreamFactory generates live REST APIs from database schemas with standardized endpoints for tables, views, and procedures in OpenAPI format. We support on-prem deployment with firewall security and include RBAC for secure, granular security controls.

See more!

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay