Grafana enables you to query, visualize, alert on, and explore your metrics, logs, and traces wherever they’re stored.
This page shows you how to integrate Grafana with a Timescale Cloud service, create a dashboard and panel, then visualize geospatial data.
Before integrating:
Create a target Timescale Cloud service. You need your connection details to follow this procedure.
This procedure also works for self-hosted TimescaleDB.
- Install self-managed Grafana or sign up for Grafana Cloud.
To connect the data in your service to Grafana:
Log in to Grafana
In your browser, log in to either:
- Self-hosted Grafana: at
http://localhost:3000/
. The default credentials areadmin
,admin
. - Grafana Cloud: use the URL and credentials you set when you created your account.
- Self-hosted Grafana: at
Add your service as a data source
- Open
Connections
>Data sources
, then clickAdd new data source
. - Select
PostgreSQL
from the list. - Configure the connection:
Host URL
,Username
,Password
, andDatabase
: configure using your connection details.Database name
: provide the name for your dataset.TLS/SSL Mode
: selectrequire
.PostgreSQL options
: enableTimescaleDB
.- Leave the default setting for all other fields.
- Open
Click
Save & test
Grafana checks that your details are set correctly.
Grafana is organized into dashboards and panels. A dashboard represents a view into the performance of a system, and each dashboard consists of one or more panels, which represent information about a specific metric related to that system.
To create a new dashboard:
On the
Dashboards
page, clickNew
and selectNew dashboard
Click
Add visualization
Select the data source
Select your service from the list of pre-configured data sources or configure a new one.
Configure your panel
Select the visualization type. The type defines specific fields to configure in addition to standard ones, such as the panel name.
Run your queries
You can edit the queries directly or use the built-in query editor. If you are visualizing time-series data, select
Time series
in theFormat
drop-down.Click
Save dashboard
You now have a dashboard with one panel. Add more panels to a dashboard by clicking
Add
at the top right and selectingVisualization
from the drop-down.
Grafana time-series panels include a time filter:
Call
$__timefilter()
to link the user interface construct in a Grafana panel with the queryFor example, to set the
pickup_datetime
column as the filtering range for your visualizations:SELECT--1--time_bucket('1 day', pickup_datetime) AS "time",--2--COUNT(*)FROM ridesWHERE $__timeFilter(pickup_datetime)Group your visualizations and order the results by time buckets
In this case, the
GROUP BY
andORDER BY
statements referencetime
.For example:
SELECT--1--time_bucket('1 day', pickup_datetime) AS time,--2--COUNT(*)FROM ridesWHERE $__timeFilter(pickup_datetime)GROUP BY timeORDER BY timeWhen you visualize this query in Grafana, you see this:
You can adjust the
time_bucket
function and compare the graphs:SELECT--1--time_bucket('5m', pickup_datetime) AS time,--2--COUNT(*)FROM ridesWHERE $__timeFilter(pickup_datetime)GROUP BY timeORDER BY timeWhen you visualize this query, it looks like this:
Grafana includes a Geomap panel so you can see geospatial data overlaid on a map. This can be helpful to understand how data changes based on its location.
This section visualizes taxi rides in Manhattan, where the distance traveled was greater than 5 miles. It uses the same query as the NYC Taxi Cab tutorial as a starting point.
Add a geospatial visualization
In your Grafana dashboard, click
Add
>Visualization
.Select
Geomap
in the visualization type drop-down at the top right.
Configure the data format
In the
Queries
tab below, select your data source.In the
Format
drop-down, selectTable
.In the mode switcher, toggle
Code
and enter the query, then clickRun
.For example:
SELECT time_bucket('5m', rides.pickup_datetime) AS time,rides.trip_distance AS value,rides.pickup_latitude AS latitude,rides.pickup_longitude AS longitudeFROM ridesWHERE rides.trip_distance > 5GROUP BY time,rides.trip_distance,rides.pickup_latitude,rides.pickup_longitudeORDER BY timeLIMIT 500;
Customize the Geomap settings
With default settings, the visualization uses green circles of the fixed size. Configure at least the following for a more representative view:
Map layers
>Styles
>Size
>value
.This changes the size of the circle depending on the value, with bigger circles representing bigger values.
Map layers
>Styles
>Color
>value
.Thresholds
> Addthreshold
.Add thresholds for 7 and 10, to mark rides over 7 and 10 miles in different colors, respectively.
You now have a visualization that looks like this:
Keywords
Found an issue on this page?Report an issue or Edit this page in GitHub.