Search code examples
mysqlgraphpanelgrafana

How to add Time series queries with grafana and MySQL?


I'm new to grafana and playing around to see if it could fit my needs for a research lab.

I'm using grafana-server Version 4.5.2 (commit: ec2b0fe)

I tried to follow the grafana documentation about mysql datasources (sorry I'm not allowed to post more than two links, just try to search in your favorite search engine...)

I have succefully added a MySQL data source.

Here is my database :

mysql> DESC meteo;
+-------------+----------+------+-----+---------+----------------+
| Field       | Type     | Null | Key | Default | Extra          |
+-------------+----------+------+-----+---------+----------------+
| id          | int(100) | NO   | PRI | NULL    | auto_increment |
| date_insert | datetime | NO   |     | NULL    |                |
| temperature | float    | NO   |     | NULL    |                |
+-------------+----------+------+-----+---------+----------------+

Following the documentation I've added a panel "Table" with the following query...

SELECT
  date_insert as 'Date',
  temperature as 'Temperature'
 FROM meteo

...and choosen "Format as Table"

The result is ok as you can see.

Grafana Panel Format Table

Now I would like to have a graph like this :

Grafana Panel Format Time series

How can I achieve this with my database ? I don't understand the doc which says :

If you set Format as to Time series, for use in Graph panel for example,

then there are some requirements for what your query returns.

Must be a column named time_sec representing a unix epoch in seconds.

Must be a column named value representing the time series value.

Must be a column named metric representing the time series name.

How can I apply this with my database ? Is it just possible ?


Solution

  • Here is the solution, thanks to the Grafana team !

    daniellee's answer