What is Grafana and why we use it
Grafana is the core of an ecosystem to monitor in real time any kind of data flux and react to it, it is a interactive dashboard tool that allow you to visualise data and automate incident detection and response.
In our case it's to visualise the evolution of the performance of our software. This allow us to make reports that have nice looking graphs and percentage comparison.
Our usecase is a bit different from the intended one because we only use it to make visualisation of data that isn't real time, most of it doesn't even really have a relation to time. This makes the exploitation of the tool a little harder but we still view it as worth it.
How to use Grafana
Here we will only talk about data-visualisation though a dashboard because it is the only feature that we really use.
If you want to learn how to setup your data-source grafana has a great onboarding system when you start to set it up.
sidenote :
We use a plugin to allow the usage of sqlite as a data-source.
This page will not include detailed step or screenshot of specific ui parts because the ui change depending on the version of grafana used.
Dashboards
The first element that you need to create is a dashboard, at first it will be empty.
In this dashboard you will be able to do 2 important things :
- create new visualisations
- change the visualisation time
Visualisations
A visualisation is a pannel where you query your data and choose the shape you want it to take, it could be a complex time-series or a simple bar-chart.
One pitfall I must warn you about is trying to make a visualisation too complex, a dashboard can hold a lot of visualisation and it is usualy better to just make two simple visualisation and put them next to each other for comparison than trying to include both data in the same one.
Visualisation time
The visualisation time is a really important part of grafana, it defines the timeframe displayed by all your visualisation on a dashboard.
It is possible to overide a specific visualisation to display a different timeframe but it is usualy better to just make another dashboard.
In the context of a real time monitoring app it is really usefull to zoom at a certain point of time to observe data flow, for example just before a major outage in service. But in our case because we don't use real time data this feature is detrimental to us, to circonvince that problem we use what is called a Transformation.
A transformation is as it names sugest a way to make a number or text into another type of data, in our scenario, to make it into a timestamp.
SQL queries
In our usecase we use sqlite as a data source so to use the data we first need to extract it with a sql query, there are some other type of data source that use different methods.
here are the main request we use :
- show the performance evolution between minor version of a specific plugin (
40 AS thresholdis used to draw a threshold line on the graph )
SELECT ram_usage, cpu_usage, disk_usage, version, 40 AS threshold FROM system_metrics_2 WHERE plugin = 'Scanner' and version > 0 and version < 1;
- same request as the n°1 except it's between two major version ( and no threshold line, can be added if needed )
SELECT ram_usage, cpu_usage, disk_usage, version FROM system_metrics_2 WHERE plugin = 'Scanner' and version = 0.1 or plugin = 'Scanner' and version = 1.0;