All Products
Search
Document Center

Tablestore:Get started with the TimeSeries model

Last Updated:Feb 27, 2025

The TimeSeries model is designed based on the characteristics of time series data. This model is suitable for scenarios such as IoT device monitoring and can be used to store data collected by devices and the monitoring data of machines. The TimeSeries model allows applications to write and read data with high concurrency and supports the storage of petabytes of data at low costs. This topic describes how to use the Tablestore CLI to get started with the TimeSeries model.

Prerequisites

An instance is created. For more information, see Create an instance.

Usage notes

The TimeSeries model is supported in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Zhangjiakou), China (Ulanqab), China (Shenzhen), China (Chengdu), China (Hong Kong), Japan (Tokyo), Malaysia (Kuala Lumpur), Germany (Frankfurt), Indonesia (Jakarta), UK (London), US (Silicon Valley), US (Virginia), SAU (Riyadh - Partner Region), and Singapore.

Procedure

Step 1: Configure information of the instance that you want to access

Run the config command to configure access information.

Before you run the command, replace the endpoint, instance name, AccessKey ID, and AccessKey secret in the command with the actual endpoint, instance name, AccessKey ID, and AccessKey secret.
config --endpoint https://myinstance.cn-hangzhou.ots.aliyuncs.com --instance myinstance --id NTSVL******************** --key 7NR2****************************************

Step 2: Create and use a time series table

After you create a time series table, you can select the time series table so that you can perform subsequent table operations or data operations on the time series table.

  1. Run the following command to create a time series table named mytable:

    create -m timeseries -t mytable --ttl -1
  2. Run the following command to use the time series table named mytable:

    use --ts -t mytable

Step 3: Perform data operations

You can write and query time series data and manage time series metadata based on your business requirements.

Write time series data

  • Insert a row of time series data.

    The following sample command shows how to insert a row of time series data to a time series table:

    putts --k '["cpu","localhost",["region=hangzhou","os=ubuntu"]]' --field '[{"c":"fieldname","v":"fieldvalue"},{"c":"bool_field","v":true},{"c":"double_field","v":1.1},{"c":"int_value","v":10,"isint":true}]' --time 1737451312000000
  • Import time series data.

    The following sample command shows how to import time series data from the import_timeseries.txt file to a time series table:

    import_timeseries --input /temp/import_timeseries.txt

    Sample configurations in the import_timeseries.txt file:

    cpu,hostname=host_0,region=cn-hangzhou usage_user=58i,usage_system=2i,usage_idle=24i 1609459200000000000
    cpu,hostname=host_1,region=cn-hangzhou usage_user=58i,usage_system=2i,usage_idle=24i 1609459200000000000

Query time series data

The following sample command shows how to query the time series data that is generated before 1667638230000000 in the time series whose metric name is cpu, data source is host_0, and tags are hostname=host_0 and region=cn-hangzhou:

You can execute SQL statements to query time series data in the table. For more information, see SQL query.
getts --k '["cpu","host_0",["hostname=host_0","region=cn-hangzhou"]]' --time_start 0 --time_end 1667638230000000 --limit 100

Manage time series metadata

  • Retrieve time series.

    The following sample command shows how to retrieve time series whose metric name is cpu and data source is host_0:

    query_ts_meta --measurement cpu --datasource host_0 --limit 10
  • Scan time series.

    The following sample command shows how to obtain up to 10 time series in a time series table:

    query_ts_meta --limit 10
  • Update a time series.

    The following sample command shows how to update the properties of a time series to hostname=host_1 and region=cn-hangzhou:

    update_ts_meta --k '["cpu","host_1",["hostname=host_1","region=cn-hangzhou"]]' --attrs '["hostname=host_1","region=cn-hangzhou"]'