Graphing Non Time Series SQL Data in Grafana
Video Lecture
Description
Grafana can graph time series data from many types of data sources extremely well. But sometimes you just want to graph, simple non time series data. I.e, data without timestamps, basic tables that show simple statistics.
Example non time series data as a flat table.
id | name | value |
---|---|---|
1 | Cat | 56 |
2 | Dog | 35 |
3 | Lizard | 41 |
4 | Crocodile | 22 |
5 | Koala | 26 |
6 | Cassowary | 29 |
7 | Peacock | 19 |
8 | Emu | 10 |
9 | Kangaroo | 13 |
We would like to see this simple example data, as a graph similar to below.
For this exercise, we can quickly create a new database named exampledb
and allow our grafana
database user select
permissions on it.
# |
|
> |
|
> |
|
You should see a new database named exampledb
.
Let's now create a simple table with some data that we can query.
>
|
|
Insert Statement
>
|
|
Check data exists
> |
|
Explore the Data in Grafana
Open the Explore tab, select MySQL as the data source and show Code
editor.
Paste in the query below.
>
|
|
If you run the command, you will have an error similar to Error 1142 (42000): SELECT command denied to user 'grafana'@'###.###.###.###' for table 'simple_table'
.
We should allow our grafana
database user select
permissions on the table.
> |
|
> |
|
> |
|
Now try to connect from Grafana again.
Convert Query to return a Time Series
Now convert it to a time series by aliasing NOW() as "time"
.
SELECT
NOW() as "time",
username,
total as ""
FROM
exampledb.simple_table
ORDER BY
id
You can test updating the data in the table, and seeing it in Grafana by opening your MySQL prompt and executing,
> |
|