Updated on 2026-02-05 GMT+08:00

Updating a Metric Definition

Function

This API is used to update a metric definition.

Calling Method

For details, see Calling APIs.

URI

PUT /v1/{project_id}/workspaces/{workspace_id}/soc/metrics/{metric_id}

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID, which is used to specify the project that a resource belongs to. You can query the resources of a project by project ID. You can obtain the project ID from the API or console. Obtaining the Project ID

Constraints

N/A

Range

N/A

Default Value

N/A

workspace_id

Yes

String

Definition

Workspace ID.

Constraints

N/A

Range

N/A

Default Value

N/A

metric_id

Yes

String

Metrics ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. You can obtain it by calling the IAM API for obtaining a user token. The user token is the value of X-Subject-Token in the response header. Obtaining a User Token

Constraints

N/A

Range

N/A

Default Value

N/A

content-type

Yes

String

Definition

Content type.

  • application/json;charset=UTF-8: common API request type

Constraints

N/A

Range

  • application/json;charset=UTF-8

Default Value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Metric name.

id

No

String

Metric ID.

metric_type

Yes

String

Indicator type. Currently, only log indicators can be created.

data_type

Yes

String

Data type. Currently, only statistics metrics can be created.

metric_dimension

No

Integer

Metric result dimension. 0: single number; 2: chart or table; and 3+: multi-label chart. If metric_type is set to DERIVED, this parameter is mandatory. If metric_type is set to COMPOUND, this parameter must be fixed at 0. In other cases, this parameter is optional.

cache_ttl

Yes

Long

Cache lifecycle, in seconds.

report_period

No

Long

Reporting period, which is mandatory for tracking metrics. The unit is second.

is_built_in

No

Boolean

Whether the metric is a system metric.

effective_column

No

String

Effective column. If this parameter is specified, the specified column is used as the metric data result.

max_query_range

No

Integer

Maximum search range supported by the metric, in days. For compound metrics, the value is the minimum value in the derived_metrics list.

derived_metrics

No

Array of derived_metrics objects

List of derived metrics. If the metric is not a compound metric, there is only one element. If the metric is a compound metric, the definition of each derived metric is included.

compound_expression

No

String

If metric_type is set to DERIVED, enter the expression of a compound metric.

metric_format

No

Array of LayoutMetricFormat objects

Metric format.

metric_expand_dim

No

MetricDimensionExpandParam object

Extended parameters of the metric dimension.

version

No

String

SecMaster edition.

Table 4 derived_metrics

Parameter

Mandatory

Type

Description

metric_dimension

Yes

Integer

Result dimension of the derived metric. 0: single number; 2: chart or table; and 3+: multi-label chart.

max_query_range

No

Integer

Maximum query range supported by the metric, in days.

date_start

No

String

Date math expression of the relative start time for the metric query range.

date_end

No

String

Date math expression of the relative end time for the metric query range.

date_format

No

String

Time format. The options are epoch_millis, epoch_second, and yyyy-MM-dd'T'HH:mm:ss.SSSZ.

query_type

Yes

String

Method for obtaining metric results. The options are cbsl, api, dsl, and sql.

query_function

Yes

String

Method for obtaining metric results. The value is of string type.

Table 5 LayoutMetricFormat

Parameter

Mandatory

Type

Description

data

No

String

Data format.

display

No

String

Display format.

display_param

No

Map<String,String>

Display parameters.

data_param

No

Map<String,String>

Data parameters.

Table 6 MetricDimensionExpandParam

Parameter

Mandatory

Type

Description

labels

Yes

Array of strings

Dimension expansion label.

functions

Yes

Array of strings

Dimension expansion method. Enter the built-in method on the metric data plane. The value of index starts from 1.

Response Parameters

Status code: 200

Table 7 Response header parameters

Parameter

Type

Description

X-request-id

String

Request ID. Format: request_uuid-timestamp-hostname.

Table 8 Response body parameters

Parameter

Type

Description

name

String

Metric name.

id

String

Metric ID.

metric_type

String

Indicator type. Currently, only log indicators can be created.

data_type

String

Data type. Currently, only statistics metrics can be created.

metric_dimension

Integer

Metric result dimension. 0: single number; 2: chart or table; and 3+: multi-label chart. If metric_type is set to DERIVED, this parameter is mandatory. If metric_type is set to COMPOUND, this parameter must be fixed at 0. In other cases, this parameter is optional.

cache_ttl

Long

Cache lifecycle, in seconds.

report_period

Long

Reporting period, which is mandatory for tracking metrics. The unit is second.

is_built_in

Boolean

Whether the metric is a system metric.

effective_column

String

Effective column. If this parameter is specified, the specified column is used as the metric data result.

max_query_range

Integer

Maximum search range supported by the metric, in days. For compound metrics, the value is the minimum value in the derived_metrics list.

derived_metrics

Array of derived_metrics objects

List of derived metrics. If the metric is not a compound metric, there is only one element. If the metric is a compound metric, the definition of each derived metric is included.

compound_expression

String

If metric_type is set to DERIVED, enter the expression of a compound metric.

metric_format

Array of LayoutMetricFormat objects

Metric format.

metric_expand_dim

MetricDimensionExpandParam object

Extended parameters of the metric dimension.

version

String

SecMaster edition.

Table 9 derived_metrics

Parameter

Type

Description

metric_dimension

Integer

Result dimension of the derived metric. 0: single number; 2: chart or table; and 3+: multi-label chart.

max_query_range

Integer

Maximum query range supported by the metric, in days.

date_start

String

Date math expression of the relative start time for the metric query range.

date_end

String

Date math expression of the relative end time for the metric query range.

date_format

String

Time format. The options are epoch_millis, epoch_second, and yyyy-MM-dd'T'HH:mm:ss.SSSZ.

query_type

String

Method for obtaining metric results. The options are cbsl, api, dsl, and sql.

query_function

String

Method for obtaining metric results. The value is of string type.

Table 10 LayoutMetricFormat

Parameter

Type

Description

data

String

Data format.

display

String

Display format.

display_param

Map<String,String>

Display parameters.

data_param

Map<String,String>

Data parameters.

Table 11 MetricDimensionExpandParam

Parameter

Type

Description

labels

Array of strings

Dimension expansion label.

functions

Array of strings

Dimension expansion method. Enter the built-in method on the metric data plane. The value of index starts from 1.

Status code: 400

Table 12 Response header parameters

Parameter

Type

Description

X-request-id

String

Request ID. Format: request_uuid-timestamp-hostname.

Table 13 Response body parameters

Parameter

Type

Description

code

String

Definition

Error code.

Range

N/A

message

String

Definition

Error description.

Range

N/A

Example Requests

Request body for updating a metric.

{
  "cache_ttl" : 10,
  "version" : "23.9.0",
  "max_query_range" : 5,
  "name" : "name",
  "metric_type" : "LOGGING",
  "data_type" : "statistics"
}

Example Responses

Status code: 200

Response succeeded.

{
  "cache_ttl" : 10,
  "compound_expression" : null,
  "data_type" : "STATISTICS",
  "derived_metrics" : [ ],
  "effective_column" : null,
  "id" : "b1f1e000-59d0-4030-bfb7-c4bff9c5ddb4",
  "is_built_in" : false,
  "max_query_range" : 5,
  "metric_dimension" : 0,
  "metric_expand_dim" : null,
  "metric_format" : [ ],
  "metric_type" : "LOGGING",
  "name" : "name",
  "report_period" : 0
}

SDK Sample Code

The SDK sample code is as follows.

Request body for updating a metric.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.secmaster.v1.region.SecMasterRegion;
import com.huaweicloud.sdk.secmaster.v1.*;
import com.huaweicloud.sdk.secmaster.v1.model.*;


public class UpdateMetricsSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        SecMasterClient client = SecMasterClient.newBuilder()
                .withCredential(auth)
                .withRegion(SecMasterRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateMetricsRequest request = new UpdateMetricsRequest();
        request.withWorkspaceId("{workspace_id}");
        request.withMetricId("{metric_id}");
        CreateMetricRequestBody body = new CreateMetricRequestBody();
        body.withDataType("statistics");
        body.withMetricType("LOGGING");
        body.withName("name");
        body.withMaxQueryRange(5);
        body.withVersion("23.9.0");
        body.withCacheTtl(10L);
        request.withBody(body);
        try {
            UpdateMetricsResponse response = client.updateMetrics(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Request body for updating a metric.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdksecmaster.v1.region.secmaster_region import SecMasterRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdksecmaster.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = SecMasterClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateMetricsRequest()
        request.workspace_id = "{workspace_id}"
        request.metric_id = "{metric_id}"
        request.body = CreateMetricRequestBody(
            data_type="statistics",
            metric_type="LOGGING",
            name="name",
            max_query_range=5,
            version="23.9.0",
            cache_ttl=10
        )
        response = client.update_metrics(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Request body for updating a metric.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := secmaster.NewSecMasterClient(
        secmaster.SecMasterClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateMetricsRequest{}
	request.WorkspaceId = "{workspace_id}"
	request.MetricId = "{metric_id}"
	maxQueryRangeCreateMetricRequestBody:= int32(5)
	versionCreateMetricRequestBody:= "23.9.0"
	request.Body = &model.CreateMetricRequestBody{
		DataType: "statistics",
		MetricType: "LOGGING",
		Name: "name",
		MaxQueryRange: &maxQueryRangeCreateMetricRequestBody,
		Version: &versionCreateMetricRequestBody,
		CacheTtl: int64(10),
	}
	response, err := client.UpdateMetrics(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Response succeeded.

400

Error response.

Error Codes

See Error Codes.