Help Center/ SecMaster/ API Reference/ API/ Metric Query/ Querying Metrics in Batches
Updated on 2024-07-25 GMT+08:00

Querying Metrics in Batches

Function

This API is used to query metrics in batches.

Calling Method

For details, see Calling APIs.

URI

POST /v1/{project_id}/workspaces/{workspace_id}/sa/metrics/hits

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

Minimum: 32

Maximum: 32

workspace_id

Yes

String

Workspace ID.

Minimum: 36

Maximum: 36

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

timespan

No

String

The time range for querying metrics. The format is ISO8601, for example, 2007-03-01T13:00:00Z/2008-05-11T15:30:00Z, 2007-03-01T13:00:00Z/P1Y2M10DT2H30M, or P1Y2M10DT2H30M/2008-05-11T15:30:00Z.

Minimum: 1

Maximum: 255

cache

No

Boolean

Indicates whether to enable the cache. The default value is true. The value false indicates that the cache is disabled.

Default: true

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is a token.

Minimum: 100

Maximum: 100000

Table 4 Request body parameters

Parameter

Mandatory

Type

Description

metric_ids

Yes

Array of strings

Specifies the metric ID list to be queried. For details about how to obtain the existing metrics, see the related information in the appendix.

Minimum: 10

Maximum: 64

Array Length: 1 - 50

workspace_ids

No

Array of strings

Workspace list. This API is mandatory when the metric supports obtaining data of multiple workspaces.

Minimum: 10

Maximum: 64

Array Length: 0 - 50

params

No

Array of Map<String,String> objects

Indicates the parameter list of the metric to be queried. Each element in the list is in K-V format of <String, String>. The number of elements must be the same as that of the metric_ids list. For details, see the appendix.

Array Length: 0 - 50

interactive_params

No

Array of Map<String,String> objects

For query the interactive parameters, if the metric supports interactive parameters, enter a parameter list in the K-V format of <String, String>. For details, see the appendix.

Array Length: 0 - 100

field_ids

No

Array of strings

Metric card ID list

Minimum: 32

Maximum: 64

Array Length: 0 - 50

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

[items]

Array of ShowMetricResultResponseBody objects

Request successful.

Table 6 ShowMetricResultResponseBody

Parameter

Type

Description

metric_id

String

Metric ID

result

result object

Metric query result.

metric_format

Array of MetricFormat objects

Metric format. The value is fixed based on different metrics.

Array Length: 0 - 64

log_msg

String

Result log information

Minimum: 0

Maximum: 1024

status

String

Query result status. The options are as follows: SUCCESS: The query is successful. FAILED: The query fails. FALLBACK: The default value is used.

Minimum: 0

Maximum: 128

Enumeration values:

  • SUCCESS

  • FAILED

  • FALLBACK

Table 7 result

Parameter

Type

Description

labels

Array of strings

Title of the metric query result table

Minimum: 0

Maximum: 999

Array Length: 0 - 999

datarows

Array<Array<Object>>

Metric query result table.

Array Length: 0 - 999

effective_column

String

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

Table 8 MetricFormat

Parameter

Type

Description

data

String

Data format

Minimum: 1

Maximum: 128

display

String

Display format

Minimum: 1

Maximum: 128

display_param

Map<String,String>

Display parameter

data_param

Map<String,String>

Data parameters

Example Requests

Query the alarm severity distribution from June 25 to the current time through the metric API.

https://{endpoint}/v1/{project_id}/workspaces/{workspace_id}/sa/metrics/hits

{
  "metric_ids" : [ "1f0f5e29-5a92-17a5-2c16-5f37c6dc109c" ],
  "params" : [ {
    "start_date" : "2024-06-25T00:00:00.000+08:00"
  } ]
}

Example Responses

Status code: 200

Request successful.

[ {
  "metric_id" : "1f0f5e29-5a92-17a5-2c16-5f37c6dc109c",
  "result" : {
    "labels" : [ "label1" ],
    "datarows" : [ [ { } ] ],
    "effective_column" : "0:1"
  },
  "status" : "SUCCESS"
} ]

Status Codes

Status Code

Description

200

Request successful.

Error Codes

See Error Codes.