All Products
Search
Document Center

Tablestore:Connect Tablestore to Grafana

Last Updated:Sep 13, 2024

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.

    Warning

    If 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:

  • 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

  1. Click Grafana plug-in for Tablestore package to download the Grafana plug-in for Tablestore package.

  2. Extract files from the package to the plugins-bundled directory of the Grafana plug-in.

  3. Modify the Grafana configuration file.

    1. Use a text editor to open the defaults.ini configuration file in the conf directory of the Grafana plug-in.

    2. Find [plugins] in the configuration file and configure the allow_loading_unsigned_plugins parameter.

      allow_loading_unsigned_plugins = aliyun-tablestore-grafana-datasource
  4. Restart the grafana-server.exe process in Task Manager.

Mac/Linux

  1. 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
  2. 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.

      Note

      In the preceding command, {PATH_TO}/grafana-{VERSION} specifies the installation path of Grafana and {VERSION} specifies the version number of Grafana.

  3. Modify the Grafana configuration file.

    1. 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.

        Note

        In the preceding file name, {PATH_TO}/grafana-{VERSION} specifies the installation path of Grafana and {VERSION} specifies the version number of Grafana.

    2. Find [plugins] in the configuration file and configure the allow_loading_unsigned_plugins parameter.

      allow_loading_unsigned_plugins = aliyun-tablestore-grafana-datasource
  4. Restart Grafana.

    1. Run the kill command to terminate the Grafana process.

    2. 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

  1. Log on to Grafana.

    1. 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 and http://localhost:3000 is entered in the address bar to go to the Grafana logon page.

    2. Enter values for the Email or username and Password parameters. Then, click Log in.

      Note

      The 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.

  2. On the Grafana homepage, click the image icon in the upper-left corner.

  3. In the left-side navigation pane, choose Connections > Data sources.

  4. On the Data sources page, click + Add new data source.

    image

  5. In the Others section of the Add data source page, click aliyun-tablestore-grafana-datasource.

  6. 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.

  7. Click Save & test.

    After the data source is added to Grafana, the Data source is working message appears.

    image

Step 3: Create a dashboard

  1. On the Grafana homepage, click the image icon in the upper-left corner.

  2. In the left-side navigation pane, click Dashboards.

  3. On the Dashboards page, click New, and then select New dashboard.

    image

  4. On the New dashboard page, click + Add visualization.

  5. In the Select data source dialog box, select the configured Tablestore data source.

    image

  6. 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.

    Important
    • You 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.

  7. Click Run SQL to execute SQL statements, view the data, and then perform debugging.

  8. Configure the dashboard and save the configurations.

    1. In the right-side pane, specify the name, type, and graph styles of the monitoring chart.

      fig_20220426_dashboard

    2. Click Apply.

    3. 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

  1. On the Grafana homepage, click the image icon in the upper-left corner.

  2. 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.