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.
Constraints
Currently, only service run logs of MQTT devices can be recorded. For details, see Table 1.
Service Type |
Service Process |
---|---|
Device status |
|
Device going offline |
|
Device message |
|
Device command |
|
Device property |
|
Device event |
|
Platform responding to a request for updating child device statuses |
|
Device downloading upgrade package |
|
Batch task |
|
Device self-registration |
|
Device authentication |
Custom device authentication result |
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
- Access the IoTDA service page and click Access Console. Click the target instance card.
- In the navigation pane, choose .
- 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
- If you use the function for the first time, you need to click Enable and Configure. Two configuration modes are available.
- One-click configuration:
- 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.
- 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
- 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:
- The device has been registered on IoTDA.
- 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:
- 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>
- 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; }
- 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:
- 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
- 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
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot