You can configure data forwarding rules to forward processed data to Time Series Database (TSDB) for storage. This topic describes how to forward data to a destination instance.

Prerequisites

  • An IoT Platform instance whose data can be forwarded to TSDB is created in a region that supports data forwarding to TSDB.
    Supported instance Supported region
    Enterprise Edition instances: Standard and Video
    • China (Shanghai)
    • Japan (Tokyo)
  • A TSDB instance that is deployed in a virtual private cloud (VPC) is created in the Japan (Tokyo) region. For more information, see TSDB documentation.
  • A data forwarding rule is created and an SQL statement that is used to process data is written. For more information, see Configure a data forwarding rule.

Background information

After you configure the data destination, the following configurations are automatically completed. Then, you can forward the device data to the TSDB instance by using the rules engine of IoT Platform.

  • IoT Platform occupies two IP addresses of the vSwitch where the TSDB instance resides. The IPv4 CIDR block of the vSwitch is added to the whitelist of the TSDB instance.
  • A managed security group is created in the VPC where the TSDB instance resides. The default name of the security group starts with sg-nsm-.

Limits

  • Data can be forwarded only within a region. For example, you can only forward data from an IoT Platform instance that is deployed in the Japan (Tokyo) region to a TSDB instance that is deployed in the Japan (Tokyo) region.
  • You can forward data only to a TSDB instance that is deployed in a VPC.
  • You can forward data only in the JSON format.
  • In the forwarded messages, all fields are written to TSDB as the metric, except for the fields that are configured as the timestamp and tag value. The data types of the metric parameter support numeric and string. If you use other data types, data may fail to be written to the database.

Usage notes

You can use the new version or old version of the data forwarding feature to forward data to Lindorm. For more information about how to use the new version of the data forwarding feature, see Use the new version of the data forwarding feature to forward data to Lindorm.

Procedure

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance that you want to manage and click the instance name to go to the Instance Details page.
    Important Enterprise Edition instances are available in the China (Shanghai) and Japan (Tokyo) regions. If the Enterprise Edition instances are unavailable in the region that you select, skip this step.
    Overview
  3. In the left-side navigation pane, choose Rules Engine > Data Forwarding.
  4. Click View next to the rule that you want to manage. The Data Forwarding Rule page appears.
    Important If the new version of the Data Forwarding page is displayed, click Back to Previous Version in the upper-right corner, and then click View in the Actions column of the rule that you want to manage.
  5. In the Forward Data section, click Add Operation.
  6. In the Add Operation dialog box, select Store Data to TSDB from the Operation drop-down list. Follow the instructions on the page to set other parameters and click OK.
    Parameter Description
    Operation Select Store Data to TSDB.
    Region The region where your IoT Platform instance is deployed: Japan (Tokyo)
    TSDB Instance Specify the TSDB instance in the VPC that you have created as the destination to which data is forwarded.
    metric Data Type Specify the data type of the metric parameter. Valid values: Numeric Type and String.

    Click the Help icon to obtain more information.

    timestamp Timestamp. The following configurations are supported:
    • Use an escape character expression ${}. For example, set the parameter to ${time}. This specifies that the parameter value corresponds to the value of the time field in the message in the data source topic.
    • Use the rules engine function timestamp(). This specifies that the parameter value is set to the timestamp of the rules engine server.
    • Enter a value. The input value must be a UNIX timestamp. For example, you can enter 1404955893000.
    Tag Name Specify the tag name that is used to identify data. The tag name can contain letters, digits, and the following special characters: :,.'/-_()[]
    Tag Value Specify the value of the tag. The following configurations are supported:
    • Use an escape character expression ${}. For example, if the structure of a message in a data source topic contains a location property whose key is city, you can set the tag value to ${city}. This specifies that the parameter value corresponds to the value of the city field in the message. We recommend that you use this configuration.
    • Use the functions specified in the rules engine, such as deviceName(). This specifies that the tag value is the name of the device. For more information about the supported functions, see Functions.
    • Enter a constant. For example, you can enter the constant beijing. The value can contain letters, digits, and the following special characters: :,.'/-_()[]
    Note
    • You can add a maximum of eight tag names and eight tag values.
    • Make sure that TSDB can obtain the configured tag names and tag values. If TSDB cannot obtain the name or value of a tag, the data cannot be written to the database.
    Role Grant IoT Platform the permissions to write data to TSDB.
  7. Go to the Data Forwarding page, find the rule that you managed, and then click Start in the Actions column of the rule.

Data forwarding examples

The following code block provides a sample SQL statement in the data forwarding rule:

SELECT time,city,power,distance FROM "/alprodu****/myDevice/user/update";

The following section shows how the rules engine processes data and writes data to TSDB based on the SQL statement.

  1. The sample SQL statement shows that the rules engine filters the time, city, power, and distance fields from the messages in the /alprodu****/myDevice/user/update topic and uses the content of the filtered fields as the content of the message to forward.

    The following example shows the content of the message to forward after data is processed based on the preceding SQL statement:

    {
    "time": 1513677897,
    "city": "beijing",
    "distance": 8545,
    "power": 93.0
    }
  2. The rules engine writes two rows of data to TSDB based on the configured data forwarding operation.

    In the example, the following data is written to TSDB:

    • Data: timestamp:1513677897, [metric:power value:93.0]
      tag: cityName=beijing
    • Data: timestamp:1513677897, [metric:distance value:8545]
      tag: cityName=beijing

    The following section describes how data is written to TSDB:

    In the preceding forwarded messages, except for the time field that is configured as the timestamp and the city field that is configured as the tag value, other fields (power and distance) are written to TSDB as the metric.