如何使用 grafana 和 MySQL 添加时间序列查询?

How to add Time series queries with grafana and MySQL?

我是 grafana 的新手,想看看它是否能满足我对研究实验室的需求。

我正在使用 grafana-server 版本 4.5.2(提交:ec2b0fe)

我尝试遵循有关 mysql 数据源的 grafana 文档(抱歉,我不允许 post 超过两个链接,只需尝试在您最喜欢的搜索引擎中搜索...)

我已成功添加 MySQL 数据源。

这是我的数据库:

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    |                |
+-------------+----------+------+-----+---------+----------------+

根据文档,我添加了一个带有以下查询的面板“Table”...

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

...并选择“格式为 Table”

结果如你所见。

Grafana Panel Format Table

现在我想要一个这样的图表:

Grafana Panel Format Time series

如何使用我的数据库实现此目的?我不明白上面写的文档:

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.

我如何将它应用到我的数据库中?这可能吗?

这是解决方案,感谢 Grafana 团队!

daniellee's answer