Creating a Metric
Function
This API is used to create a metric.
The format for reporting indicators is as follows:
csb_sa_metric_track_soc_flow_yyyy.MM.dd_ttl180 { "name": "soc_flow", //Metric name. "data_type": "STATISTICS", //Metric type. "report_period": 86400, //Reporting period, in seconds. "report_time": 1662368225038, "data": { //Reported based on the definition of each subsystem. "msg_id": "7ffe0474-5254-4783-bb1d-c014a8c791fe-soc", "project_id": "9391876dbccb44319e09ecc617481c93", "domain_id": "dfaf9864b95c448797b5dc0f00709a55", "resource_id": "xxxx", "resource_type": "xxxx", "workspace_id": "988ca0eb-b81e-4c24-9a85-d83ece4525ee", "flow": 123456789, //Long, aggregated based on project_id. "flow_type": 0/1, //0: number of message events, 1: data traffic. "flow_unit": "byte"//Default value: an empty string, indicating the number of messages or incidents. ----> The number of messages or incidents corresponding to SOC. This field is an empty string. "" } }
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/workspaces/{workspace_id}/soc/metrics
|
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 |
Request 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. Constraints N/A Range Default Value N/A |
|
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. |
|
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. |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
X-request-id |
String |
Request ID. Format: request_uuid-timestamp-hostname. |
|
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. |
|
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. |
|
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. |
|
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
|
Parameter |
Type |
Description |
|---|---|---|
|
X-request-id |
String |
Request ID. Format: request_uuid-timestamp-hostname. |
|
Parameter |
Type |
Description |
|---|---|---|
|
code |
String |
Definition Error code. Range N/A |
|
message |
String |
Definition Error description. Range N/A |
Example Requests
Request body for creating a metric.
{
"report_period" : 0,
"cache_ttl" : 10,
"is_built_in" : false,
"version" : "23.9.0",
"max_query_range" : 5,
"name" : "name",
"metric_type" : "LOGGING",
"data_type" : "statistics",
"metric_dimension" : 0
}
Example Responses
Status code: 200
Request 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 creating 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 58 59 |
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 CreateMetricSolution { 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(); CreateMetricRequest request = new CreateMetricRequest(); request.withWorkspaceId("{workspace_id}"); CreateMetricRequestBody body = new CreateMetricRequestBody(); body.withMetricDimension(0); body.withDataType("statistics"); body.withMetricType("LOGGING"); body.withName("name"); body.withMaxQueryRange(5); body.withVersion("23.9.0"); body.withIsBuiltIn(false); body.withCacheTtl(10L); body.withReportPeriod(0L); request.withBody(body); try { CreateMetricResponse response = client.createMetric(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 creating 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 |
# 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 = CreateMetricRequest() request.workspace_id = "{workspace_id}" request.body = CreateMetricRequestBody( metric_dimension=0, data_type="statistics", metric_type="LOGGING", name="name", max_query_range=5, version="23.9.0", is_built_in=False, cache_ttl=10, report_period=0 ) response = client.create_metric(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 creating 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 |
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.CreateMetricRequest{} request.WorkspaceId = "{workspace_id}" metricDimensionCreateMetricRequestBody:= int32(0) maxQueryRangeCreateMetricRequestBody:= int32(5) versionCreateMetricRequestBody:= "23.9.0" isBuiltInCreateMetricRequestBody:= false reportPeriodCreateMetricRequestBody:= int64(0) request.Body = &model.CreateMetricRequestBody{ MetricDimension: &metricDimensionCreateMetricRequestBody, DataType: "statistics", MetricType: "LOGGING", Name: "name", MaxQueryRange: &maxQueryRangeCreateMetricRequestBody, Version: &versionCreateMetricRequestBody, IsBuiltIn: &isBuiltInCreateMetricRequestBody, CacheTtl: int64(10), ReportPeriod: &reportPeriodCreateMetricRequestBody, } response, err := client.CreateMetric(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 |
Request succeeded. |
|
400 |
Error response. |
Error Codes
See Error Codes.
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