Display data using Grafana

更新时间:
复制 MD 格式

After you connect Tablestore to Grafana, you can use Grafana to visualize data from Tablestore.

Prerequisites

Background information

Grafana is an open source visualization and analytics platform. It supports data query and visualization for various data sources, such as Prometheus, Graphite, OpenTSDB, InfluxDB, Elasticsearch, MySQL, and PostgreSQL. For more information, see the official Grafana documentation.

After you ingest table data from Tablestore into Grafana, Grafana can generate dashboards based on the table data. This lets you display data to users in real time.

Notes

Tablestore supports data visualization with Grafana in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), China (Shenzhen), and Singapore.

Step 1: Install the Tablestore plugin

Windows

  1. Download the Tablestore Grafana plugin package.

  2. Decompress the Tablestore Grafana plugin package and move the resulting folder to the plugins-bundled directory in your Grafana installation.

  3. Modify the Grafana configuration file.

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

    2. In the [plugins] section of the configuration file, set the allow_loading_unsigned_plugins parameter.

      allow_loading_unsigned_plugins = aliyun-tablestore-grafana-datasource
  4. In Task Manager, restart the grafana-server.exe process.

Mac/Linux

  1. Run the following command to download the Tablestore Grafana plugin package.

    wget https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20220527/ygdf/tablestore-grafana-plugin-1.0.0.zip
  2. Decompress the Tablestore Grafana plugin package to the Grafana plugins directory.

    Run the command that corresponds to your Grafana installation method.

    • For Grafana installed using Yellowdog Updater, Modified (YUM) or RPM Package Manager (RPM) (Linux only): unzip tablestore-grafana-plugin-1.0.0.zip -d /var/lib/grafana/plugins

    • For Grafana installed from a .zip file: unzip tablestore-grafana-plugin-1.0.0.zip -d {PATH_TO}/grafana-{VERSION}/data/plugins

      Note

      In this path, {PATH_TO}/grafana-{VERSION} is the installation path of Grafana and {VERSION} is the version number of Grafana.

  3. Modify the Grafana configuration file.

    1. Open the configuration file from the appropriate directory.

      • For Grafana installed using YUM or RPM (Linux only): /etc/grafana/grafana.ini

      • For Grafana installed from a .zip file: {PATH_TO}/grafana-{VERSION}/conf/defaults.ini

        Note

        In this path, {PATH_TO}/grafana-{VERSION} is the installation path of Grafana and {VERSION} is the version number of Grafana.

    2. In the [plugins] section of the configuration file, set the allow_loading_unsigned_plugins parameter.

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

    1. Use the kill command to stop the Grafana process.

    2. Run the following command to start Grafana.

      • For Grafana installed using YUM or RPM (Linux only): systemctl restart grafana-server

      • For Grafana installed from a .zip file: ./bin/grafana-server web

Step 2: Configure the data source

  1. Log on to Grafana.

    1. In a browser, enter http://<x.x.x.x>:3000/ to open the Grafana logon page.

      Note

      <x.x.x.x> represents the IP address of the server where Grafana is installed. For example, if Grafana is installed on Windows, the logon address is http://localhost:3000.

    2. Enter your Email or username and Password, and click Log in.

      Note

      The default username and password for the initial logon are both admin. When you log on for the first time, you are prompted to change the initial password.

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

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

  4. On the Data Sources page, click + Add New Data Source.

    image

  5. On the Add data source page, under Others, click aliyun-tablestore-grafana-datasource.

  6. On the Settings page, configure the parameters as described in the following table.

    Parameter

    Example

    Description

    Name

    aliyun-tablestore-grafana-datasource

    The name of the data source. You can customize the name. The default value is aliyun-tablestore-grafana-datasource.

    Endpoint

    https://myinstance.cn-hangzhou.ots.aliyuncs.com

    The endpoint of the Tablestore instance. Enter the endpoint 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 the Alibaba Cloud account or RAM user that has permissions to access Tablestore.

    AccessKey

    ********************************

    The AccessKey secret of the Alibaba Cloud account or RAM user that has permissions to access Tablestore.

  7. Click Save & test.

    If the connection is successful, the Data source is working message is displayed.

    image

Step 3: Create a dashboard panel

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

  2. In the left navigation pane, click Dashboards.

  3. On the Dashboards page, click New and 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. On the Edit page, configure the query conditions in the Query section.

    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
    • In the WHERE clause, use a predefined macro to filter the time range. For example, use $__unixMicroTimeRangeFilter. To view more time macro functions, click Show Help on the configuration page.

    • If you display the data in a time series chart, you must return a time column that is represented as a numeric timestamp and configure the name of the time column.

    Format As

    Timeseries

    The format for processing the results. Valid values:

    • Timeseries (default): A standard time series chart.

    • FlowGraph: A multi-dimensional chart.

    • Table: A standard table.

    Time Column

    _time

    The name of the time column in the returned data. The time column is used as the horizontal axis of the time series chart. This parameter is available when you set Format As to Timeseries or FlowGraph.

    Aggregation Column

    _field_name#:#_double_value

    Converts multi-row, single-column data at the same point in time to single-row, multi-column data at the same point in time. This is useful for transforming single-value model data generated by Tablestore time series SQL into multi-value model data. This parameter is available when you set Format As to FlowGraph. The format is <data_point_name_column>#:#<numeric_value_column>.

  7. Click Run SQL to execute the SQL statement and debug the data.

  8. Set and save the dashboard panel.

    1. In the panel on the right, set the name, type, and display style of the monitoring chart.

      fig_20220426_dashboard

    2. In the upper-right corner, click Apply.

    3. In the upper-right corner, click Save. In the Save dashboard dialog box, set the Title, Description, and Folder, and then click Save.

Step 4: View monitoring data

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

  2. In the navigation pane on the left, choose Dashboards. Click the monitoring dashboard in the target directory to view all of its monitoring charts.