After Tablestore is connected to Grafana, you can use Grafana to display data in Tablestore.
Prerequisites
The following operations are performed in the Resource Access Management (RAM) console:
A RAM user is created and the AliyunOTSFullAccess policy is attached to the RAM user to grant the RAM user the permissions to manage Tablestore. For more information, see Create a RAM user and Grant permissions to a RAM user.
WarningIf the AccessKey pair of your Alibaba Cloud account is leaked, your resources are exposed to potential risks. We recommend that you use the AccessKey pair of a RAM user to perform operations. This prevents the AccessKey pair of your Alibaba Cloud account from being leaked.
The following operations are performed in the Tablestore console:
Tablestore is activated and an instance is created. For more information, see Activate Tablestore and Create an instance.
A data table or time series table is created. For more information, see Operations on a data table and Operations on time series tables.
A mapping table is created for the data table or time series table in Tablestore. For more information, see Create a mapping table for a table and Use SQL to query time series data.
Open source Grafana whose version is later than 8.0.0 is installed. In the examples in this topic, Grafana v11.1.3 is installed. For information about how to install Grafana, see Install Grafana.
Background information
Grafana is an open source visualization and analytics platform that supports data query and visualization for various data sources such as Prometheus, Graphite, OpenTSDB, InfluxDB, Elasticsearch, MySQL, and PostgreSQL. For more information, see the Grafana official documentation.
After you add a Tablestore data source to Grafana, Grafana displays the data of Tablestore on a dashboard in real time.
Usage notes
You can connect Tablestore in the following regions to Grafana: China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), China (Shenzhen), and Singapore.
Step 1: Install the Grafana plug-in for Tablestore
Windows
Click Grafana plug-in for Tablestore package to download the Grafana plug-in for Tablestore package.
Extract files from the package to the plugins-bundled directory of the Grafana plug-in.
Modify the Grafana configuration file.
Use a text editor to open the defaults.ini configuration file in the conf directory of the Grafana plug-in.
Find [plugins] in the configuration file and configure the allow_loading_unsigned_plugins parameter.
allow_loading_unsigned_plugins = aliyun-tablestore-grafana-datasource
Restart the grafana-server.exe process in Task Manager.
Mac/Linux
Run the following command to download the Grafana plug-in for Tablestore package:
wget https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20220527/ygdf/tablestore-grafana-plugin-1.0.0.zip
Extract files from the Grafana plug-in for Tablestore package to a directory of the Grafana plug-in.
Run the following command to extract files from the Grafana plug-in for Tablestore package based on the method you use to install the Grafana plug-in:
If you use a yum repository or an RPM package to install the Grafana plug-in in Linux, run the unzip tablestore-grafana-plugin-1.0.0.zip -d /var/lib/grafana/plugins command.
If you use a .tar.gz file to install the Grafana plug-in, run the unzip tablestore-grafana-plugin-1.0.0.zip -d {PATH_TO}/grafana-{VERSION}/data/plugins command.
NoteIn the preceding command,
{PATH_TO}/grafana-{VERSION}
specifies the installation path of Grafana and{VERSION}
specifies the version number of Grafana.
Modify the Grafana configuration file.
Go to the directory of Grafana and open the configuration file.
If you use a yum repository or an RPM package to install Grafana in Linux, open the /etc/grafana/grafana.ini file.
If you use a .tar.gz file to install Grafana, open the {PATH_TO}/grafana-{VERSION}/conf/defaults.ini file.
NoteIn the preceding file name,
{PATH_TO}/grafana-{VERSION}
specifies the installation path of Grafana and{VERSION}
specifies the version number of Grafana.
Find [plugins] in the configuration file and configure the allow_loading_unsigned_plugins parameter.
allow_loading_unsigned_plugins = aliyun-tablestore-grafana-datasource
Restart Grafana.
Run the kill command to terminate the Grafana process.
Run the following command to start Grafana.
If you use a yum repository or an RPM package to install Grafana in Linux, run the systemctl restart grafana-server command.
If you use a .tar.gz file to install Grafana, run the ./bin/grafana-server web command.
Step 2: Add a data source
Log on to Grafana.
Enter
http://<x.x.x.x>:3000/
in the address bar of a browser to go to the Grafana logon page.Note<x.x.x.x>
specifies the IP address of Grafana. In this example, Grafana is installed in Windows andhttp://localhost:3000
is entered in the address bar to go to the Grafana logon page.Enter values for the Email or username and Password parameters. Then, click Log in.
NoteThe default username and password that are used to log on to Grafana are both admin. The first time you log on to Grafana, change the default password as prompted.
On the Grafana homepage, click the icon in the upper-left corner.
In the left-side navigation pane, choose .
On the Data sources page, click + Add new data source.
In the Others section of the Add data source page, click aliyun-tablestore-grafana-datasource.
On the Settings page, configure the parameters. The following table describes the parameters.
Parameter
Example
Description
Name
aliyun-tablestore-grafana-datasource
The name of the data source. You can retain the default value or enter a custom name. Default value: aliyun-tablestore-grafana-datasource.
Endpoint
https://myinstance.cn-hangzhou.ots.aliyuncs.com
The endpoint of the Tablestore instance. Configure this parameter based on the Tablestore instance that you want to access. For more information, see Endpoints.
Instance
myinstance
The name of the Tablestore instance.
AccessId
************************
The AccessKey ID of your Alibaba Cloud account or a RAM user that has the permissions to access Tablestore.
AccessKey
********************************
The AccessKey secret of your Alibaba Cloud account or a RAM user that has the permissions to access Tablestore.
Click Save & test.
After the data source is added to Grafana, the Data source is working message appears.
Step 3: Create a dashboard
On the Grafana homepage, click the icon in the upper-left corner.
In the left-side navigation pane, click Dashboards.
On the Dashboards page, click New, and then select New dashboard.
On the New dashboard page, click + Add visualization.
In the Select data source dialog box, select the configured Tablestore data source.
In the Query section of the Edit page, specify the query conditions.
The following table describes the parameters.
Parameter
Example
Description
Query
SELECT * FROM your_table WHERE $__unixMicroTimeRangeFilter(_time)AND _m_name = "your_measurement" AND tag_value_at(_tags, "your_tag")="your_tag_value"LIMIT 1000
The SQL query statement. For more information, see Query data.
ImportantYou must specify a time macro function in the WHERE clause to filter data based on the time range. In this example, the
$__unixMicroTimeRangeFilter
time macro function is used. You can click Show Help on the configuration page to view more time macro functions.If you want data to be displayed as a time series chart, you must specify that the time column represented by a numeric timestamp must be returned and specify the name of the time column.
Format As
Timeseries
The method that you want to use to display the query results. Default value: Timeseries. Valid values:
Timeseries: displays the query results as a regular time series chart.
FlowGraph: displays the query results as a multi-dimensional chart.
Table: displays the query results as a regular table.
Time Column
_time
The name of the time column in the query results that are returned. The time column is used as the x-axis of the time series chart. You can configure this parameter only when you set the Format As parameter to Timeseries or FlowGraph.
Aggregation Column
_field_name#:#_double_value
The name of the single column whose data in multiple rows at a specific point in time you want to convert into data in multiple columns of a single row at the specified point in time. This parameter is used to convert data in single-value model into data in multi-value model. The data in single-value model is the results that are obtained when you use SQL to query a time series table in Tablestore. You can configure this parameter only when you set the Format As parameter to FlowGraph. The value of this parameter is in the
<Data point name column>#:#<Data value column>
format.Click Run SQL to execute SQL statements, view the data, and then perform debugging.
Configure the dashboard and save the configurations.
In the right-side pane, specify the name, type, and graph styles of the monitoring chart.
Click Apply.
Click Save in the upper-right corner. In the Save dashboard dialog box, configure the Title, Description, and Folder parameters, and then click Save.
Step 4: View monitoring data
On the Grafana homepage, click the icon in the upper-left corner.
In the left-side navigation pane, click Dashboards. On the page that appears, click the name of the dashboard that you want to view. Then, you can view the monitoring data on the dashboard.