Updated on 2024-11-06 GMT+08:00

Run Logs (New Version)

Overview

IoTDA records connections with devices and applications and reports them as logs to Log Tank Service (LTS). LTS provides real-time query, mass storage, structured processing, and visualized chart analysis.

You do not need to manually create log groups, log streams, and forwarding rule action when using the new version of run logs. The IoT platform automatically completes configurations for you. You can long in to the IoT platform to view the run logs.

Figure 1 Process of run logs

Constraints

Currently, only service run logs of MQTT devices can be recorded. For details, see Table 1.

Table 1 Service type

Service Type

Service Process

Device status

Device going online

Device going offline

Device message

Application requesting message delivery to devices

Platform delivering messages to devices

Device reporting messages

Device command

Application requesting command delivery to devices

Platform delivering commands to devices

Platform receiving device response to commands

Device property

Application requesting device property modification

Platform delivering property modification to devices

Device reporting properties

Gateway reporting device properties in batches

Device event

Platform notifying a gateway of new child device connection

Platform notifying a gateway of child device deletion

Gateway synchronizing child device information

Gateway updating child device status

Gateway requesting for adding child devices

Platform responding to a request for adding child devices

Gateway requesting for deleting child devices

Platform responding to a request for deleting child devices

Gateway updating child device status

Platform responding to a request for updating child device statuses

Platform delivering a command to obtain version information

Device reporting the software and firmware versions

Platform delivering an upgrade command

Device reporting the upgrade status

Device requesting a URL for file upload

Platform delivering a temporary URL for file upload

Device reporting file upload results

Device requesting a URL for file download

Platform delivering a temporary URL for file download

Device reporting file download results

Device requesting time synchronization

Platform responding to a request for time synchronization

Device reporting information

Platform delivering a log collection notification

Device reporting log content

Platform delivering a configuration notification

Device reporting the configuration response

Device downloading upgrade package

Batch task

Subtask execution result of a batch task

Device self-registration

Device self-registration result.

Device authentication

Custom device authentication result

Table 2 Format of batch task run logs

Field

Description

appId

Application ID.

deviceId

Device ID.

categoryName

Log type: batch.task.

operation

Action. Set this parameter to the ID of a batch task. For details, see Create a Batch Task.

request

Request content in JSON format.

{

"task_type": "createDevices", / / Task type

"package_id": "f2303267a6e8f0053037c2a9", // Software/Firmware upgrade package

"package_ids": ["65f3ebe2682b9f4bcc38baad"] // Software/Firmware upgrade package

}

NOTE:

When the batch task type is softwareUpgrade or firmwareUpgrade, the package_id and package_ids parameters are supported.

response

Response content in JSON format.

Success:

{

"output" : "xxxxxxxxxxxx"

}

Failure:

{

"error" : {

"error_code" : "IOTDA.XXXXX",

"error_msg" : "XXXXX."

}

}

status

Execution result. Subtask status. Options: Success, Fail, Stopped, or Removed.

Procedure

  1. Access the IoTDA service page and click Access Console. Click the target instance card.
  2. In the navigation pane, choose O&M > Run Logs.
  3. If you are using run logs of an earlier version, you can click New Version in the upper right corner. The new Run Logs page is displayed. If you have used the new version, the new version page is auto displayed.

    Figure 2 Run logs - Going to new version

  4. If you use the function for the first time, you need to click Enable and Configure. Two configuration modes are available.

    1. One-click configuration:
      The platform automatically creates a log group and log stream, configures log structuring, and sets corresponding forwarding rules and actions.
      Figure 3 Run log - One-click configuration
    2. Custom configuration

      You can flexibly set rules, log groups, and log streams for run logs.

      If you configure a structuring rule for the log stream, the platform will modify the structuring automatically.

      Figure 4 Run log - Custom configuration

    Deleting a forwarding rule whose Data Source is Run log may affect functions. Exercise caution.

  5. After configuration, you can view or search for run logs (by time, log type, device ID, action, and request content) to analyze services. Run logs are stored in the LTS for 30 days by default. You can modify the retention duration to 365 days at most on the console.

    Figure 5 Run log - Modifying the storage time

    Run logs are stored in LTS. LTS provides a free quota of 500 MB per month. You can click Quota in the upper right corner to configure the Extra Log Collection function. You can also go to LTS Configuration Center and set the log resource quota alarm. For details, see What Is Log Tank Service?

    • If you enable Extra Log Collection, LTS will continue to collect log data when the monthly free quota (500 MB) is reached. You will be billed for the excess part on a pay-per-use basis. For details, see Billing.
    • If you disable Extra Log Collection, LTS will discard log data when the monthly free quota (500 MB) is reached.
      Figure 6 Run log - Quota setting

  6. One or more service types can be enabled for run logs. You can click Configure Run Log and change the log collection type in the displayed dialog box. If you do not select any type, the function of collecting logs is disabled.

    Figure 7 Run log - Configuring the log switch

Example of Run Logs

This section describes how to use the Java SDK to report messages, trigger run logs to be transferred to LTS, and check message reporting logs on IoTDA. JDK 1.8 or later is used.

Prerequisites:

  1. The device has been registered on IoTDA.
  2. The run logs of the new version has been enabled and configured, and the device message log switch has been enabled.

Configure the SDK on the device side:

  1. Configure the Maven dependency of the SDK on devices.

    <dependency>
    	<groupId>com.huaweicloud</groupId>
    	<artifactId>iot-device-sdk-java</artifactId>
    	<version>1.1.4</version>
    </dependency>

  2. Configure the SDK and device connection parameters on devices. Note: Replace the domain name (domain), device ID (deviceId), and device secret (secret) in the actual code.

    // Load the CA certificate of the IoT platform. For details about how to obtain the certificate, visit https://support.huaweicloud.com/intl/en-us/devg-iothub/iot_02_1004.html.
    URL resource = BroadcastMessageSample.class.getClassLoader().getResource("ca.jks");
    File file = new File(resource.getPath());
    
    // The format is ssl://Domain name:Port number.
    // To obtain the domain name, log in to the Huawei Cloud IoTDA console. In the navigation pane, choose Overview and click Access Details in the Instance Information area. Select the access domain name corresponding to port 8883.
    String serverUrl = "ssl://{domain}:8883";
    // Device ID created on the IoT platform
    String deviceId = "{deviceId}";
    // Secret corresponding to the device ID
    String deviceSecret = "{secret}";
    // Create a device.
    IoTDevice device = new IoTDevice(serverUrl, deviceId, deviceSecret, file);
    if (device.init() != 0) {
        return;
    }

  3. Report a message.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    device.getClient().reportDeviceMessage(new DeviceMessage("hello"), new ActionListener() {
        @Override
        public void onSuccess(Object context) {
            log.info("reportDeviceMessage ok");
        }
    
        @Override
        public void onFailure(Object context, Throwable var2) {
            log.error("reportDeviceMessagefail: "+ var2);
        }
    });
    

Verify the setting:

  1. Run the SDK code on the device. If the following information is displayed on the console, the device goes online and reports messages successfully.

    2023-04-27 17:05:26  INFO MqttConnection:88 - Mqtt client connected. address :ssl://{domain}:8883
    2023-04-27 17:05:26  INFO MqttConnection:214 - publish message topic =  $oc/devices/{deviceId}/sys/messages/up, msg = {"name":null,"id":null,"content":"hello","object_device_id":null}
    2023-04-27 17:05:26  INFO MessageSample:43 - reportDeviceMessage ok

  2. Check run logs on the console. You can check the records of device login and logout and messages reported by devices.

    Figure 8 Run logs - Log example