ApsaraDB for SelectDB is compatible with MySQL 5.7 connection protocols, so you can connect it to Managed Service for Grafana as a MySQL data source. This topic walks you through adding a SelectDB instance as a data source and building dashboards with table panels and time series charts.
Prerequisites
Before you begin, ensure that you have:
-
Public endpoint: A public endpoint for your SelectDB instance. See Apply for or release a public endpoint.
-
Credentials: The username and password for your SelectDB instance. Use a read-only account with minimal permissions to reduce security risk.
-
Workspace: A Grafana workspace created in Managed Service for Grafana. See Create and manage a Grafana workspace.
-
IP whitelist: The public IP address of your Grafana workspace added to the IP address whitelist of your SelectDB instance. To get the workspace's public IP address: Then add that IP address to the SelectDB whitelist. See Configure an IP address whitelist.
-
Log on to the ARMS console. In the left-side navigation pane, choose Managed Service for Grafana > Workspace Management.
-
Click the ID or name of your workspace. In the Public IP Address section, note the IP address.
-
Billing
Managed Service for Grafana Shared Edition generates no fees. See Billing rules for details.
Step 1: Add SelectDB as a data source
Managed Service for Grafana does not have a native SelectDB data source type. Because SelectDB is compatible with MySQL 5.7 connection protocols and syntax, use the MySQL data source type.
-
Log on to the ARMS console. In the left-side navigation pane, choose Managed Service for Grafana > Workspace Management.
-
On the Workspace Management page, click the URL in the URL column for your workspace to open Grafana.
Log on with the Grafana administrator account and the password you set when creating the workspace, or click Sign in with Alibaba Cloud to use your current Alibaba Cloud account.
-
Grafana 9.x
In the left-side navigation pane, click the
icon. Click Add data source, then click MySQL.Grafana 10.x
-
Click the
icon in the upper-left corner. -
In the left-side navigation pane, choose Management > Data sources.
-
On the Data sources tab, click Add data source, then click MySQL.
-
-
On the Settings page, configure the following parameters. For additional parameters, see the Grafana MySQL data source documentation.
Parameter Description Name A name for this data source Host The public endpoint of your SelectDB instance, in the format <Public endpoint>:<MySQL port>. For example:selectdb-cn-bcd****-public.selectdbfe.rds.aliyuncs.com:9030. Find the endpoint on the details page of your SelectDB instance.Database The name of your SelectDB instance User The username for your SelectDB instance. Use a read-only account with minimal permissions. Password The password for your SelectDB instance -
Click Save & Test. If
Database Connection OKappears, the data source is connected. If an error appears, see Troubleshooting.
Step 2: Build a dashboard
The following example uses a test_table with columns id, place, user, operate, operate_time, and count. The sample data:
SELECT * FROM `test_table` WHERE operate_time < '2022-07-20 03:00:00';
| ID | place | user | operate | operate_time | count |
|---|---|---|---|---|---|
| 1 | China (Hangzhou) | User A | Browse | 2022/7/20 0:00 | 3 |
| 2 | China (Hangzhou) | User A | Browse | 2022/7/20 1:00 | 8 |
| 3 | China (Hangzhou) | User A | Browse | 2022/7/20 2:00 | 13 |
| 11 | China (Beijing) | User A | Browse | 2022/7/20 0:00 | 23 |
| 12 | China (Beijing) | User B | Browse | 2022/7/20 1:00 | 18 |
| 13 | China (Beijing) | User B | Browse | 2022/7/20 2:00 | 3 |
| 21 | China (Beijing) | User C | Browse | 2022/7/20 0:00 | 13 |
| 22 | China (Beijing) | User C | Browse | 2022/7/20 1:00 | 22 |
| 23 | China (Beijing) | User C | Browse | 2022/7/20 2:00 | 23 |
Create a table panel
-
In the left-side navigation pane, click the
icon, then click New dashboard. -
Click Add a new panel.
-
On the Visualizations tab on the right side of the Edit Panel page, select Table.
-
On the Query tab, select the data source you added in Step 1.
-
In section A, enter the following query and set Format as to Format as Table:
SELECT id AS "Serial number", place AS "City", user AS "User", operation AS "Operation", count AS "Number of occurrences", operate_time AS "Operation time" FROM test_table -
Click Apply in the upper-right corner.
Create a time series chart
-
In the upper-right corner of the dashboard, click the
icon, then click Add a new panel. -
On the Visualizations tab of the Edit Panel page, select Time series.
-
On the Query tab, select the data source you added in Step 1.
-
In the A panel, configure the query settings:
Setting Value Time column operate_timeMetric column userSELECT countFormat as Time Series
-
(Optional) To display the data as a column chart, go to the Graph styles section in the right-side panel and set Style to Bars.

-
Click Apply in the upper-right corner.
Troubleshooting
If the connection test fails after clicking Save & Test, check the following:
-
Incorrect connection details: Verify that the Host, Database, User, and Password values match your SelectDB instance configuration. The host must follow the format
<Public endpoint>:<MySQL port>(for example, port9030). -
IP address not whitelisted: Confirm that the public IP address of your Grafana workspace is added to the IP address whitelist of your SelectDB instance. See Configure an IP address whitelist. Find the workspace's public IP address in the Public IP Address section of the workspace details page.
What's next
-
Explore additional visualization types and query options in the Grafana documentation.
-
Manage your Grafana workspaces in Managed Service for Grafana.