All Products
Search
Document Center

Connect Grafana to TSDB

Last Updated: Sep 10, 2020

Grafana is an open source visualization tool to display large amounts of metric data. It is widely used in scenarios such as Internet application analysis, industrial monitoring, meteorological monitoring, home automation, and process management. After you connect TSDB to Grafana, you can use the visualization features provided by Grafana to monitor and analyze the data in TSDB.

This topic describes how to connect TSDB to Grafana.

Environment preparation

This topic describes how to install Grafana on an ECS instance, and connect Grafana to a TSDB instance through a VPC.

Make sure that you have a TSDB instance and an ECS instance that are in the same VPC. The ECS instance must meet the following requirements:

  • The operating system must be 64-bit CentOS 7.3.
  • The minimum instance specification is a single-core CPU and 2 GB memory. The available space of the disk must be no less than 10 GB.
  • The IP address of the ECS instance connected to the VPC is added to the whitelist of the TSDB instance.
  • You have assigned the ECS instance a public IP address if you need to use a browser to access Grafana through the Internet.
  • You have created a security group rule in the ECS console to enable access to the ECS instance over port 3000.

Note: For more information about how to use ECS, see the ECS documentation.

Install and configure Grafana

Perform the following steps to install and start Grafana on the ECS instance.

  1. Run the following command on the ECS instance to install Grafana:

    1. $ sudo yum install https://dl.grafana.com/oss/release/grafana-6.2.2-1.x86_64.rpm

    Note: For more information about how to install Grafana, see Install on RPM-based Linux (CentOS, Fedora, OpenSuse, Red Hat).

  2. Run the following command to start Grafana:

    1. $ sudo service grafana-server start

Connect a TSDB instance to Grafana

The following steps describe how to connect a TSDB instance to Grafana.

  1. Connect to the ECS instance over port 3000 in your browser to go to the Grafana logon page. For example, if the public IP address of your ECS instance is 106.15.195.23, enter http://106.15.195.23:3000/ in the address bar of your browser.

  2. On the Grafana logon page, enter adminfor both the username and the password. The Grafana homepage appears.

  3. Create a data source in Grafana. You must specify the following parameters and can retain the default values for the other parameters.

  • Type: Select OpenTSDB.

  • HTTP URL: Enter the VPC IP address of the TSDB instance. You can view the address in the TSDB console. Go to the Instance Details page of the TSDB instance. VPC Network Address is displayed in the Basic Information section.

  • Version: Select ==2.3.

    add data source

    Click Save & Test. The message Data source is working indicates that Grafana is connected to the TSDB instance.

You can create and use dashboards in Grafana. For more information about how to create dashboards, see Grafana documentation.

The following examples describe how to use Grafana to display time series data in TSDB databases.

Create a monitoring dashboard that shows specific metrics

  1. On the homepage of Grafana, choose Create > Dashboard, as shown in the following figure.

    Note: The following screenshots in this topic show the interface of Grafana 6.2. The interface of Grafana varies depending on the version of Grafana. Therefore, the actual interface may be different from the screenshots in this topic.

    Create a dashboard

    If a dashboard has already been created for the TSDB instance, you can select the existing dashboard.

  2. On the New dashboard page, click New Panel. In the dialog box that appears, click Add Query, as shown in the following figure.

    New Panel

  3. On the page that appears, configure parameters as needed.

    New Panel

    1. Specify the metric that you need to monitor, and whether to aggregate timelines of the metric.
    2. Configure a downsampling rule, including the interval, Aggregator, and Fill parameters.
    3. Group the timelines to monitor and add tags to each timeline group. If you need to monitor timelines corresponding to all tag values of a tag, enter an asterisk as the tag value: *Note: For more information about the aggregators that are supported by TSDB, see Single-value data queries.

    You can also use Grafana to display data of multi-value data models. If you enter a metric of the single-value or multi-value data model, the drop-down list only displays the name of the metric. If you enter an at sign @following the name of the metric, the drop-down list displays all the fields of the metric, and you can select a field based on your needs. Note: Grafana displays data of numeric types only. TSDB supports the numeric values, strings, and Boolean values.grafana_multi_fields

Use variables to simplify timeline filtering

As described in the preceding section, you can specify the timelines that you need to monitor by specifying the metric, tag key, and tag value. However, if there are multiple timelines and the number of timelines is increasing at a high rate, you must specify the parameters one after one to display new timelines in the created panel. To simplify the procedure, Grafana provides the variables feature.

The following steps describe how to create a variable of a specified tag and use the variables feature to filter timelines to be displayed.

  1. On the Home Dashboard page, click the Settings icon.

    The Settings icon on the Home Dashboard page

  2. On the Variables page, configure the variable to be created and specify how to fetch variable values. The parameters are described as follows:

    • Data source: Select OpenTSDB.
    • Query: Enter a query variable that Grafana provides for OpenTSDB as needed. In this example, the tag_values query variable is used to fetch tag values.

    Configure a variable

    • TSDB supports all the query variables that Grafana provides for OpenTSDB:
      • metrics(prefix) : returns all metrics that use the specified prefix. The return value can be empty.
      • tag_names(metric) : returns all tag keys for the specified metric.
      • tag_values(metric, tagKey) : returns all tag values for the specified metric and tag key.
      • suggest_tagk(prefix): returns all tag values for all metrics that use the specified prefix.
      • suggest_tagv(prefix) : returns all tag values for all metrics that use the specified prefix.

    For more information about the preceding query variables, see the Grafana documentation.

    Note: Although the preceding part indicates that the query variables return all results, the current version of Grafana only returns a limited number of results. Therefore, some metrics, tag keys, or tag values may not be returned. The Grafana community is already aware of this issue. However, in Grafana version 6.2.2 and earlier versions, this issue is not fixed. If you encounter this issue, you can avoid it by modifying the query criteria.

  3. After you configure the variable, you can use $variable to reference the query variable when you create or edit a panel in the dashboard.

    using_variables_in_panel

    You do not need to edit the panel again when new timelines are generated based on new tag values.