You can access Tablestore in the Tablestore console, in the Tablestore CLI, or by using Tablestore SDKs. You can get started with Tablestore in the Tablestore console. This topic describes how to manage the TimeSeries model in the Tablestore console.
Prerequisites
Before you use Tablestore, make sure that you have an Alibaba Cloud account and you have completed the real-name verification. If you do not have an Alibaba Cloud account, the system prompts you to Create an account when you activate Tablestore..
Step 1: Activate Tablestore
If Tablestore is activated, skip this operation. You must activate Tablestore only once. You are not charged when you activate Tablestore.
- Log on to the Tablestore product page.
- Click Get it Free.
- On the Tablestore (Pay-as-you-go) page, click Buy Now.
- On the Confirm Order page, select I have read and agree to Tablestore (Pay-as-you-go) Agreement of Service and click Activate Now. After you activate Tablestore, click Management Console to access the Tablestore console.
You can also click Console in the upper-right corner of the homepage. Click the
icon. In the left-side navigation pane, choose to go to the Tablestore console.
Step 2: Create an instance for the TimeSeries model
- Log on to the Tablestore console.
- On the Overview page, click Create Instance for TimeSeries Model.
- In the top navigation bar, select a region. For example, you can select China (Hangzhou) or China (Shenzhen).
- In the Create Instance for TimeSeries Model dialog box, specify values for the Instance Type, Instance Name, and Instance Description parameters based on your business requirements. For more information about the naming conventions for instances and how to select an instance type, see Instance.Important
- You cannot change the instance type after the instance is created.
- Each Alibaba Cloud account can create up to 10 instances. The name of an instance must be unique within the region where the instance resides.
- Click OK.
Step 3: Create a time series table
- Log on to the Tablestore console.
- On the Overview page, click the name of the required instance or click Manage Instance in the Actions column of the required instance.
- On the Instance Details tab, click the Time Series Tables tab.
- On the Time Series Tables tab, click Create Time Series Table. Note You can also click Generate Demo with One Click to create a test table with sample data for a quick start. When you create a time series table, the system performs some initialization operations. Therefore, you need to wait for dozens of seconds until the time series are displayed.
- In the Create Time Series Table dialog box, specify Name and Time to Live as described in the following table.
Parameter Description Name The name of the time series table, which is used to identify the time series table in an instance. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_). The name must start with a letter or an underscore (_).
The name of a time series table cannot be the same as the name of an existing data table.
Time to Live The retention period of the data in the time series table. Unit: seconds. If the system detects that the difference between the current time and the time column that is passed to the table exceeds the specified TTL value, the system automatically deletes the expired data. Important In the time series table, the system determines the time when the data is generated based on the time column that is passed to the table, not the time when the data is written to the table.The value of this parameter must be -1 or a value that is greater than or equal to 86400 seconds (one day).
- Click OK.
After the time series table is created, you can view the time series table on the Time Series Tables tab. If the time series table is not displayed in the list of time series tables, click the
icon to refresh the list of time series tables.
Step 4: Write data to the time series table
Write time series data to the time series table in the Tablestore console. Time series data consists of metadata and data. If you do not create metadata before you write the time series data, the system automatically extracts the metadata from the written data.
- On the Time Series Tables tab, click the name of the time series table and then click the Query Data tab or click Manage Data in the Actions column that corresponds to the time series table.
- (Optional) Create a time series.
- On the Query Data tab, click Add Timeline.
- In the Add Timeline dialog box, configure the metadata of the time series. The following table describes the parameters.
Parameter Description Metric name The name of a physical quantity or metric for the data in the time series, such as cpu or net, which specifies that the CPU usage or network usage is recorded in the time series. Data Source The identifier of the data source for the time series. This parameter can be empty. Tag The tag of the time series. You can customize multiple key-value pairs of the string type. Property The property column of the time series, which is used to record some property information of the time series. - Click OK.
- Insert data.
- Click Insert Data.
- In the Insert Data dialog box, specify Time and Attribute Column.
- Click OK.
Step 5: Retrieve time series
Retrieves all the time series that meet the specified conditions.
- On the Query Data tab, click Query Data in the upper-right corner.
- In the Query Data dialog box, specify Metric Name and Data Source, and click Add in the Tag, Property, and Updated At sections to add conditions. The following figure shows an example on how to query the time series in which the metric name is cpu and the tags contain os=Ubuntu16.10.
- Click OK.
The time series that meet the conditions are displayed on the Query Data tab.
Step 6: Query time series data
Query the data in a time series within a specific time range.
- On the Query Data tab, click Query Data in the Actions column that corresponds to the time series whose data you want to query.
- Select Time Range or Microsecond Timestamp from the drop-down list of Search Method, specify the time, and click Search.
The data that meets the conditions is displayed on the Query Data tab. The query results can be displayed in a list or figure.
The following figure shows an example of the query results in a list.The following figure shows an example of the query results in a figure.Note Different colors in the figure represent different data columns. If you move the pointer over the data trend line, the values of the corresponding data columns are displayed. You can also select or clear specific data columns to display the required data columns.
Step 7: Use SQL to query data
SQL queries are compatible with the query syntax of MySQL. After you create a time series table and create a mapping table for the time series table in SQL, you can use SQL to access data in the table.
You can create three types of mapping tables for a time series table in SQL to query data. For more information, see Use SQL to query time series data.
- On the Overview page, click the name of the required instance or click Manage Instance in the Actions column of the required instance.
- On the Query by Executing SQL Statement tab, select a mapping table to query data based on your business requirements.
- To retrieve a time series, select a mapping table for metadata of time series and execute the SELECT statement to query the time series.
For example, if you want to query the time series whose metric type is basic_metric by using the
timeseries_table::meta
mapping table for metadata of time series, execute the following SQL statement:SELECT * FROM `timeseries_table::meta` WHERE _m_name = "basic_metric" LIMIT 100;
- To query time series data by using the mapping table in the single-value model, select the mapping table in the single-value model and execute the SELECT statement to query time series data that meets the query conditions.
For example, if you want to query data in the time series whose metric type is basic_metric by using the
timeseries_table
mapping table in the single-value model, execute the following SQL statement:SELECT * FROM timeseries_table WHERE _m_name = "basic_metric" LIMIT 10;
- To query time series data by using a mapping table in the multi-value model, create a mapping table in the multi-value model and execute the SELECT statement to query time series data that meets the query conditions.
For example, if you want to query information about the metrics in the time series whose cpu value is greater than 20.0 by using the
timeseries_table::muti_model
mapping table in the multi-value model, execute the following SQL statement:SELECT cpu,memory,disktop FROM `timeseries_table::muti_model` WHERE cpu > 20.0 LIMIT 10;
For more information about how to create a mapping table in the multi-value model for a time series table, see Create mapping tables in the multi-value model for time series tables.
- To retrieve a time series, select a mapping table for metadata of time series and execute the SELECT statement to query the time series.