By default, you can view the logs generated in the last seven days in the Device Log module of the IoT Platform console. You can also export logs from the module to a Logstore of Log Service for persistent storage. After you enable the IoT Platform log dump feature, you can query and analyze logs, view and subscribe to log reports, and configure alerts in the IoT Platform console.

Prerequisites

Log Service is activated. For more information, see Resource management overview.

Usage notes

The log dump feature is available only for Alibaba Cloud accounts. RAM users are unable to use this feature.

When the log dump feature is enabled, the logs are shipped to and stored in Alibaba Cloud Log Service. You are charged for storing logs in the Logstore based on the pricing of Log Service. For more information, see Overview.

Enable the IoT Platform log dump feature

If you want to store logs from more than one product for an extended period, you must enable the log dump feature for each product.

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance and click the instance name to go to the Instance Details page.
    Notice Enterprise Edition instances are available only in the China (shanghai) and Japan (Tokyo) region. If your IoT Platform is not activated in the China (shanghai) or Japan (Tokyo) region, skip this step.
    Overview
  3. In the left-side navigation pane, choose Maintenance > Device Log.
  4. Select a product and click the IoT Platform Log Dump tab.
  5. Click Enable.
  6. Follow the on-screen instructions to enable the IoT Platform log dump feature.
    Note If Log Service is not activated, you can click Enable to go to the Log Service activation page.
    1. In the dialog box that appears, click Create next to the Role and Log Storage Location sections.
      Note If Created is displayed next to the Role and Log Storage Location sections, skip this step.
    2. Click OK.
    After you enable the IoT Platform log dump feature for the product, IoT Platform automatically creates a log storage location and a service-linked role that is used to export logs.
    • Service-linked role: You can use this role to obtain permissions to export logs. For more information, see AliyunServiceRoleForIoTLogExport service linked role.
    • Log storage location:
      • Project: iot-log-${uid}-${regionId}. Replace the ${uid} variable with your Alibaba Cloud account ID and the ${regionId} variable with the ID of the region where IoT Platform resides.
      • Logstore: iot-logs.

      All your products connected to IoT Platform share the log storage location. You can identify the logs of a product based on the ProductKey. For more information, see IoT Platform logs.

  7. Specify the retention period of logs.
    Logs exported from IoT Platform are deleted when their retention period ends. You can set the retention period to 1 to 3,000 days. The default log retention period is 7 days. You can also turn on the Permanent Storage switch to retain logs permanently.

    On the IoT Platform Log Dump tab, click Set log save time. In the message that appears, click OK. On the Logstore Attributes page, click Modify, set the Data Retention Period parameter, and then click Save.

Use the log query and analysis feature

After you enable the IoT Platform log dump feature, you can perform the following operations on the IoT Platform Log Dump tab:

  • Raw Logs:
    Operation Description
    Query and analyze logs The Raw Logs tab allows you to use SQL statements to query logs within a specified period of time and perform statistical analysis. For more information about the SQL syntax, see Search syntax and Log analysis overview.
    View charts The Graph tab allows you to view the generated charts.
    Aggregate logs The LogReduce tab allows you to aggregate similar logs and obtain a more comprehensive view of your business.
    Perform quick analysis After you query logs, you can analyze the query result and view the distribution of a field in the result.
    Configure an alert rule If an alert condition is met, IoT Platform sends an alert by text message, phone call, email, or DingTalk notification.
  • Log Report:
    Operation Description
    View reports You can view log reports in a specified time range. Log reports reflect the statuses and exceptions of devices. For more information about log reports, see the following table that describes various log reports.

    By default, a log report shows the data of the last hour that starts and ends on the hour. The data is collected at an interval of one minute in line charts.

    • To specify a time range, you can click Time Range in the upper-right corner of the Log Report tab or choose More icon > Select Time Range in the upper-right corner of a chart.
    • To change the resolution of your line chart, go to the Raw Logs tab and create an SQL statement that queries data collected at a specified interval. For more information about the SQL syntax, see Date and time functions.

      For example, you can use the following statement to set the time interval to one hour: bizCode:device | SELECT date_format(date_trunc('hour',__time__), '%m-%d %H:%i') AS Time, count(1) AS count , operation GROUP BY Time, operation ORDER BY Time limit 1440.

    Subscribe to reports IoT Platform regularly converts reports into images and sends these images to the specified contacts by using emails or DingTalk chatbots.
    Table 1. Log reports
    Report Chart type Description
    Number of Times Device Online & Offline Line chart The line chart shows the number of times that devices are connected to IoT Platform and the number of times that devices are disconnected from IoT Platform in a specified period of time.
    Device Uplink & Downlink Messages Line chart The line chart shows the number of upstream messages and the number of downstream messages in a specified period of time.
    Top 20 Devices by Uplink&Downlink Message List The list shows the top 20 devices that send or receive the most upstream or downstream messages, and the number of messages of each device.
    Error Distribution for Data Parsing Script Pie chart The pie chart shows the distribution of data parsing errors in a specified period of time.

    You can query logs by error code and view the details of data parsing errors in logs. This helps improve a data parsing script effectively.

    Top 10 Devices by Data Parsing Script Error List The list shows the top 10 devices on which the most data parsing errors occur, and the number of errors that occur on each device in a specified period of time.

    You can query logs by device name and view the details of data parsing errors in logs. This helps improve a data parsing script effectively.

    Error Distribution for TSL Validation Pie chart The pie chart shows the distribution of Thing Specification Language (TSL) validation errors in a specified period of time.

    You can query logs by error code, view the details of TSL validation errors in logs, and troubleshoot errors.

    Top 10 Devices by TSL Validation Error List The list shows the top 10 devices on which the most TSL validation errors occur, and the number of errors that occur on each device in a specified period of time.

    You can query logs by device name, view the details of TSL validation errors in logs, and troubleshoot errors.

    Server-side Subscription Messages Forwarded Line chart The line chart shows the total number of messages that are forwarded by an Advanced Message Queuing Protocol (AMQP) or Message Service (MNS) server-side subscription in a specified period of time.
    Last 20 Device Anomaly Messages Pie chart The pie chart shows the last 20 device error messages.

    You can query logs by device name and error code, view the details of device error messages in logs, and troubleshoot errors.

    Cloud Service Messages Forwarded Line chart The line chart shows the total number of messages that are forwarded by the data forwarding feature in a specified period of time.
    Last 20 Data Forwarding Errors List The list shows the last 20 data forwarding errors of the rules engine in a specified period of time.

    You can query logs by device name and error code, view the details of data forwarding errors for the rules engine in logs, and troubleshoot errors.

    Error Distribution for Cloud API Calls Pie chart The pie chart shows the distribution of errors in API calls in a specified period of time.

    You can query logs by API operation name and troubleshoot errors based on log details and error codes.

Disable the IoT Platform log dump feature

You can disable the IoT Platform log dump feature for a specific product at any time as needed to save storage space.

  1. Log on to the IoT Platform console . On the Overview page, find the instance that you want to manage and click the instance.
  2. In the left-side navigation pane, choose Maintenance > Device Log.
  3. Select a product and click the IoT Platform Log Dump tab.
  4. Click Stop Dump. In the message that appears, click OK.
    After the IoT Platform log dump feature is disabled, the newly generated IoT Platform logs are no longer exported to your Logstore. Logs that have already been exported to Log Service are not immediately deleted. They are deleted when the specified log retention period ends.