我想为两个预定义存储桶中超过 15 分钟间隔的 SQL 查询存储数据构建一个 Grafana 热图。表格视图很好,但热图视图同时显示计数和存储桶。
查询:
SELECT
updated,
CASE
WHEN score > 0 AND score < 10 THEN 0
ELSE 1
END as bucket,
COUNT(*)
FROM table
WHERE $__timeFilter(updated)
GROUP BY FLOOR(UNIX_TIMESTAMP(updated)/(15 * 60)), bucket
如您所见,有两个存储桶,按 15 分钟间隔分组。 Grafana 热图表视图: Grafana 热图表格视图
如何在热图中可视化每个存储桶中的项目数量? Grafana 展示了这一点: Grafana 热图
--
UPD:已解决。当然,我错过了教程中显示存储桶位于不同列中的部分:
SELECT
updated,
SUM(CASE WHEN score > 0 AND score < 10 then 1 else 0 end) AS A,
SUM(CASE WHEN score >= 10 then 1 else 0 end) AS B
FROM table
WHERE $__timeFilter(updated)
GROUP BY FLOOR(UNIX_TIMESTAMP(updated)/(15 * 60))
解决了。当然,我错过了教程部分,显示存储桶位于不同的列中:
SELECT
updated,
SUM(CASE WHEN score > 0 AND score < 10 then 1 else 0 end) AS A,
SUM(CASE WHEN score >= 10 then 1 else 0 end) AS B
FROM table
WHERE $__timeFilter(updated)
GROUP BY FLOOR(UNIX_TIMESTAMP(updated)/(15 * 60))