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.
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.
Perform the following steps to install and start Grafana on the ECS instance.
Run the following command on the ECS instance to install Grafana:
$ 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).
Run the following command to start Grafana:
$ sudo service grafana-server start
The following steps describe how to connect a TSDB instance to Grafana.
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 184.108.40.206, enter http://220.127.116.11:3000/ in the address bar of your browser.
On the Grafana logon page, enter adminfor both the username and the password. The Grafana homepage appears.
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.
Click Save & Test. The message
Data source is workingindicates 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.
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.
If a dashboard has already been created for the TSDB instance, you can select the existing dashboard.
On the New dashboard page, click New Panel. In the dialog box that appears, click Add Query, as shown in the following figure.
On the page that appears, configure parameters as needed.
- Specify the metric that you need to monitor, and whether to aggregate timelines of the metric.
- Configure a downsampling rule, including the interval, Aggregator, and Fill parameters.
- 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.
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.
On the Home Dashboard page, click the Settings icon.
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_valuesquery variable is used to fetch tag values.
- 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.
After you configure the variable, you can use
$variableto reference the query variable when you create or edit a panel in the dashboard.
You do not need to edit the panel again when new timelines are generated based on new tag values.