Grafana: Difference between revisions

From Leo's Notes
This page was last edited on 13 January 2021, at 22:31.
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..."
 
mNo edit summary
Line 1: Line 1:
== Pie Graph using MySQL ==
Grafana is a tool to generate graphs and dashboards.
 
== Random Notes ==
 
===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.
With the following query, I am able to generate a two column result set which I want to put into a pie graph.
{{Highlight
{{Highlight
Line 7: Line 11:
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.
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.
{{Highlight
{{Highlight
| code = 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
| code = 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
| lang = sql
| lang = sql
}}
}}
=== Ordering Series ===
When making a line graph, I wanted to order series in a specific order. The best way I found was to just have multiple queries selecting specific series in a particular order.

Revision as of 22:31, 13 January 2021

Grafana is a tool to generate graphs and dashboards.

Random Notes

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

Ordering Series

When making a line graph, I wanted to order series in a specific order. The best way I found was to just have multiple queries selecting specific series in a particular order.