3.1. Grafana connector#

3.1.1. Introduction#

Official QuasarDB Grafana plugin. It extends QuasarDB’s support to allow integration with the Grafana analytics and monitoring platform. You may read and download the connector’s code from GitHub at https://github.com/bureau14/qdb-grafana-plugin

../../_images/grafana_dash.png

3.1.2. Prerequisites#

This documentation assumes you have:

  • Grafana installed and running.

  • Both the QuasarDB daemon qdbd and the REST API qdb_rest running.

3.1.3. Installation#

The easiest way to install the plugin is via the Grafana CLI

grafana-cli --pluginUrl https://github.com/bureau14/qdb-grafana-plugin/archive/|version_full|.zip plugins install qdb-grafana-datasource

Alternatively, you can clone the git repository to your Grafana plugins directory (this is usually /var/lib/grafana/plugins on Linuxed-based systems)

cd /var/lib/grafana/plugins
git clone https://github.com/bureau14/qdb-grafana-plugin.git

Finally, restart your Grafana server and the plugin will be added automatically.

3.1.4. Configuration#

Navigate your web browser to Grafana’s datasource configuration, and click Add data source. You will see QuasarDB as one of the available data sources.

Note

It is recommended to leave Access set to Server (Default) unless you specifically know otherwise.

If your cluster is not secured you just need to fill in the REST API URL (default is http://localhost:40080) into the URL field as shown below:

../../_images/grafana_plugin_configuration_unsecured.png

If your cluster is secured make sure to use the secure REST API URL (default is https://localhost:40493) when filling in the URL field.

Note

You may need to check Skip TLS Verify under Auth settings if you are using a self-signed TLS certificate.

Check the Use Secure Cluster checkbox and fill in the User name and User secret fields using the information found in your user private key file as shown below:

../../_images/grafana_plugin_configuration_secured.png

After you are done, click Save & Test and you are ready to starting creating visualizations using QuasarDB.

3.1.5. Usage#

3.1.5.1. Quering#

You can add a visualization using QuasarDB by selecting the QuasarDB Data Source when creating a new visualization.

In addition to normal query syntax you can use the $__range and $__interval variables provided by Grafana.

For example the query:

SELECT * FROM measurements IN RANGE(2007, 2008) GROUP BY 1h

Could be written to use Grafana’s variables like this:

SELECT * FROM measurements IN $__range GROUP BY $__interval

For more information on query syntax see our query language reference

3.1.5.2. Query variables#

Query variables enable you to create more interactive and dynamic dashboards by writing a data source query that can return a list of tables, column values, tag values. Query variables support number and string values.

For more information on how to use Grafana variables check official documentation.

3.1.5.2.1. Adding query variables#

  1. In your dashboard view go to dashboard settings -> variables and click on add new variable.

    ../../_images/add-variable-1.png ../../_images/add-variable-2.png ../../_images/add-variable-3.png
  2. In query options select your QuasarDB datasource

  3. Insert query in Query textbox

  4. Run query to verify results, apply changes.

    ../../_images/add-variable-4.png

Note

Query variables are formated as column_name=column_value. This makes it easier to reuse in queries. If no column_name is provided (e.g: when listing tables) query variables are formated as column_value only.

3.1.5.2.2. Creating query variables using simplified query syntax#

For simpler queires where you want to select distinct values from column you can use simplified query syntax. This reduces the likelihood of errors in queries and speeds up creating simple variables.

For more complex queries you can use your own queries.

Example usage of simplified query syntax in Grafana:

Query:

SELECT column FROM table GROUP BY column

can be written as:

table.column

Note

Table names containing ., / charactes should be placed inside double quotes.

../../_images/query-variable-creation.png

Note

By default if Include all option checkbox is checked All variable is set to 1=1.

3.1.5.2.3. Quering using query variables#

Single value variables are replaced with their values.

For example:

Grafana query:

SELECT * FROM measurements WHERE $sensor_id

will be translated to:

SELECT * FROM measurements WHERE sensor_id='sensor1'

You can olso use multiple values of a variable in query by selecting Multi value checkbox when creating it. By default all vaues are joined with OR. You can change this behaviour by including variable inside one of special variables listed below:

  • $__or - splits variables with OR

  • $__and - splits variables with AND

  • $__comma - splits variables with ,

Examples:

Grafana query:

SELECT * FROM measurements WHERE ${sensor_id}

will be translated to:

SELECT * FROM measurements WHERE (sensor_id='sensor3' OR sensor_id='sensor2')
../../_images/quering-using-multiple-variables-1.png

Grafana query:

SELECT * FROM measurements WHERE $__or($sensor_type)

will be translated to:

SELECT * FROM measurements WHERE (sensor_type='temperature' OR sensor_type='vibration')
../../_images/quering-using-multiple-variables-2.png

Grafana query:

SELECT * FROM $__comma($tables) WHERE $__or($sensor_id)

will be translated to:

SELECT * FROM foo_03, measurements WHERE (sensor_id='sensor2' OR sensor_id='sensor3)
../../_images/quering-using-multiple-variables-3.png