Grafana

From Leo's Notes
Revision as of 00:08, 28 October 2020 by Leo (talk | contribs) (Created page with "== Pie Graph using MySQL == With the following query, I am able to generate a two column result set which I want to put into a pie graph. {{Highlight | code = SELECT requested...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 28 October 2020, at 00:08.

Pie Graph using MySQL

With the following query, I am able to generate a two column result set which I want to put into a pie graph.

SELECT requested_cpu, COUNT(requested_cpu) FROM `jobs` GROUP BY requested_cpu ORDER BY `COUNT(requested_cpu)` DESC

However, the Grafana Pie Graph plugin requires the result to be a time series. To work around this, add the timeseries with the current timestamp and ensure that the metric is a char type.

SELECT now() as time_sec, COUNT(requested_cpu) as `value`, CONVERT(requested_cpu, char) as metric FROM `jobs` WHERE   $__timeFilter(started)   GROUP BY requested_cpu