Help Center/ Workspace/ Best Practices/ Interconnecting with LTS to Collect Workspace Monitoring Metrics
Updated on 2026-05-18 GMT+08:00

Interconnecting with LTS to Collect Workspace Monitoring Metrics

Scenarios

Workspace provides multiple types of desktop statistics. For instance, you can learn desktop statuses by users, user groups, terminal types, and time.

Prerequisites

You have purchased VPC endpoints by referring to Buying a VPC Endpoint.
  • To enable a function to access resources in a VPC, you need to purchase VPC endpoints and configure an agency with VPC management permissions for the function. You need to purchase the following endpoints:
    • com.myhuaweicloud.cn-south-1.ces
    • com.myhuaweicloud.cn-south-1.lts-access
    • com.myhuaweicloud.cn-south-1.workspace
  • When purchasing VPC endpoints, make sure to select the same VPC for all of them.
  • If you configure public network access when creating a function, you do not need to create VPC endpoints.

Step 1: Creating and Configuring a Function

Create an event function by referring to Creating an Event Function.

When creating a function, set Runtime to Python 3.9.

Configuring Basic Settings

Dynamically adjust the timeout interval based on the service logic, data volume, and execution frequency. You are advised to set the timeout interval to 60 seconds in most service scenarios.

  1. Click the name of the function you created. The basic information page of the function is displayed.
  2. Click the Configuration tab and set Execution Timeout (s) to 60.

    Figure 1 Setting the executing timeout interval

  3. Click Save.

Creating the Function Trigger

Create a trigger based on the service. You are advised to use a cron expression to define trigger rules. For example, you can schedule the screen recording reporting to run every hour. As desktop recording relies on data reported by Cloud Eye Agent, it is recommended that the previous hour's data be reported at the 40th minute of each hour. User recording can be reported once in the early morning every day.

  1. On the function details page, choose Configuration > Triggers > Create Trigger.

    Figure 2 Creating a timer trigger

    Table 1 Trigger parameters

    Parameter

    Description

    Example

    Trigger Type

    Select Timer.

    Timer

    Timer Name

    Specify a custom trigger name. The name can contain letters, digits, underscores (_), and hyphens (-). It must start with a letter and cannot exceed 64 characters.

    Timer-Workspace

    Trigger Rule

    Define the trigger rule. You can select Fixed rate or Cron expression.

    • Fixed rate: The function is triggered at a fixed interval of minutes, hours, or days, with maximum values of 60, 24, and 30, respectively.
    • Cron expression: The function is triggered based on a complex rule. For example, you can set a function to be executed at 08:30:00 every Monday to Friday. For more information, see Cron Expression Rules.

    Cron expression

    40 * * * * ?

    Enable Trigger

    Determine whether to enable the timer trigger. If this parameter is disabled, the function will not be triggered at the specified frequency.

    Enabled

    Additional Information

    This is an optional parameter. The additional information you configure will be put into the user_event field of the timer event source. For details, see Supported Trigger Events.

    -

  2. Click OK.

Configuring Function Permissions

  1. On the basic function information page, choose Configuration > Permissions.
  2. Click Create Agency on the right of Agency.

    Figure 3 Creating an agency

  3. On the IAM console, choose Agencies from the navigation pane, and click Create Agency in the upper right corner.

    Figure 4 Creating an agency

  4. Set agency parameters

    • Agency Name: Enter a custom agency name.
    • Agency Type: Select Cloud service.
    • Cloud Service: Select FunctionGraph.
    • Validity Period: Retain the default value Unlimited.
      Figure 5 Configuring an agency

  5. Click Finish.
  6. In the displayed dialog box, click Authorize.
  7. On the displayed page, click Create Policy.

    Figure 6 Creating a policy

  8. Enter a policy name and select JSON for Policy View.

    Figure 7 Configuring a custom policy

  9. Copy the following content into the text box.

    {
        "Version": "1.1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "workspace:users:list",
                    "workspace:desktops:listDetail",
                    "workspace:connections:securityList",
                    "workspace:screenRecord:listOperations",
                    "workspace:statistics:listUserMetrics",
                    "workspace:screenRecord:list"
                ]
            },
            {
                "Effect": "Allow",
                "Action": [
                    "ces:metricData:list"
                ]
            },
            {
                "Effect": "Allow",
                "Action": [
                    "lts:logs:upload"
                ]
            },
            {
                "Effect": "Allow",
                "Action": [
                    "vpc:ports:delete",
                    "vpc:ports:get",
                    "vpc:ports:create",
                    "vpc:vpcs:get",
                    "vpc:subnets:get",
                    "vpc:publicIps:list",
                    "vpc:securityGroups:get"
                ]
            },
            {
                "Effect": "Allow",
                "Action": [
                    "nat:natGateways:list",
                    "nat:snatRules:list"
                ]
            }
        ]
    }

  10. Click Create.
  11. Select the created agency and click Next.
  12. Retain the default value under Scope and click OK.
  13. On the basic function information page, choose Configuration > Permissions.
  14. Select the created agency from the Agency drop-down list.

    Figure 8 Permission settings

  15. Click Save.

Configuring Function Network Settings

You can configure the network to allow a function to access resources in a VPC or from a public network. The function accesses the public network with the default NIC and shared bandwidth. For the best possible bandwidth, performance, and reliability, enable VPC access.

  1. On the basic function information page, choose Configuration > Network.
  2. On the Network page, enable VPC access and configure required parameters.

    Figure 9 Enabling VPC access
    • VPC: Select the VPC EP created in Prerequisites from the drop-down list.
    • Subnet: The subnet in the VPC is used by default.

  3. Click Save.

Configuring Environment Variables

  1. On the basic function information page, choose Configuration > Environment Variables.
  2. Click Edit Environment Variables. On the displayed page, choose JSON.

    Figure 10 Configuring environment variables

  3. Configure environment variables based on the following template, edit the variables based on the description, and copy them into the JSON text box.

    Replace the values of the following parameters:

    {
        "region": "cn-south-1",
        "ip": "100.xxx.xxx.xxx",
        "project_id": "xxx",
        "log_group_id": "xxx",
        "log_stream_id": "xxx"
    }
    • region: Set this parameter based on the current site. For example, set it to cn-south-1 for CN South-Guangzhou.
    • ip: Obtain the value by parsing the domain name for accessing Workspace.
      1. Press Win+R. In the Run dialog box, enter cmd and press Enter.
      2. Run the following commands to obtain the IP address:

        ping workspace.{region_id}.myhuaweicloud.com

        Replace region_id with the actual region ID.

    • project_id: Obtain the value by referring to Obtaining a Project ID.
    • log_group_id: Obtain the value by referring to 2.
    • log_stream_id: Obtain the value by referring to 2.

Executing Code

  1. On the basic function information page, click the Code tab.
  2. Choose File > New File.

    Figure 11 Creating a file

  3. Rename the new file index.py.

    Figure 12 Renaming a file

  4. Test the required code and copy the sample code in Step 3: Deploying Code to index.py.

    Modify the code based on site requirements.

  5. Click Test.

    Figure 13 Testing code

  6. Configure LTS logs by referring to 3.

Step 3: Deploying Code

The following sample code illustrates how to use the FunctionGraph to periodically query Workspace API results, including statistics about user connections, desktop performance, and screen recording operations, and to report the data to LTS. You can view the query results on the LTS console.

Step 3: Configuring LTS Logs

Creating a Log Group and Stream

  1. Perform the operations in Creating a Log Group and Creating a Log Stream.
  2. Perform the operations in Obtaining Log Group and Log Stream IDs.

Configuring Cloud Structuring Parsing and Setting Indexes

After configuring cloud structuring parsing, set indexes and enable auto configuration. Once the indexes are configured, review the fields and report the indexes again to ensure the changes are applied.

  1. In the log management area, click the name of the created log group. The log stream page is displayed.
  2. In the navigation pane, click Log Settings. On the Cloud Structuring Parsing page, select JSON.
  3. Click Select from Existing Logs, select the required raw log events, and click OK.

    Figure 14 Setting of cloud structuring parsing

  4. Click Intelligent Extract and then Save.
  5. Click the Index Settings tab and click Auto Configure.

    Figure 15 Index settings

  6. Click OK.

Configuring log dashboard

After logs are collected and structured, create a dashboard and add a chart for the dashboard on the LTS console. You can then run SQL statements in the visualization widget and interactive search to view the results. For details, see Creating a Dashboard.

When creating a dashboard, you can select Add Chart under Add Chart.

  1. In the navigation pane, choose Dashboards.
  2. Click the name of the created dashboard to view logs.

    Figure 16 Viewing logs