Grafana is widely used to visualize data via an extensive ecosystem of widgets and plugins. QuestDB connects to Grafana using its Postgres endpoint.

Prerequisites

Install Grafana for your platform. You will need QuestDB to be running and accessible, you can do so from Docker, the binaries or Homebrew for macOS users.

Add a data source

  1. Open Grafana’s UI (by default available at http://localhost:3000)
  2. Go to the Configuration section and click on Data sources
  3. Click Add data source
  4. Choose the PostgreSQL plugin and configure it with the following settings:
  1. host: localhost:8812
  2. database: qdb
  3. user: admin
  4. password: quest
  5. SSL mode: disable
  1. When adding a panel, use the “text edit mode” by clicking on the pencil icon and add your query

Macros

To simplify syntax and to allow for dynamic parts, like date range filters, the query can contain macros.

$__timeFilter(timestamp)

This macro tells Grafana to send the start-time and end-time defined in the dashboard to the QuestDB server. It translates to:

  1. timestamp BETWEEN
  2. '2018-02-01T00:00:00Z' AND '2018-02-28T23:59:59Z'

$__interval

This macro calculates a dynamic interval based on the time range applied to the dashboard. By using this function, the sampling interval changes automatically as the user zooms in and out of the panel.

Example query

  1. SELECT
  2. pickup_datetime AS time,
  3. avg(trip_distance) AS distance
  4. FROM taxi_trips
  5. WHERE $__timeFilter(pickup_datetime)
  6. SAMPLE BY $__interval;