Updated on 2024-07-02 GMT+08:00

Querying the Log Histogram

Function

This API is used to query the distribution of reported log events that contain a specified keyword over a certain period. If no keyword is specified, the distribution of all log events reported over the period is returned.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/lts/keyword-count

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain a project ID, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID.

Minimum: 32

Maximum: 32

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token obtained from IAM. For details about how to obtain a user token, see Obtaining a User Token.

Minimum: 1000

Maximum: 2000

Content-Type

Yes

String

Set this parameter to application/json;charset=UTF-8.

Minimum: 30

Maximum: 30

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

start_time

Yes

String

Start time.

end_time

Yes

String

End time.

step_interval

Yes

Long

Time step, in milliseconds (ms). Recommended formula: (end_time-start_time)/1000 x 1000/60, where /1000 x 1000 means rounding to an integer.

NOTE:

If the calculated result is less than or equal to 1000, the value 1000 is used.

group_id

Yes

String

Log group ID.

Minimum: 36

Maximum: 36

stream_id

Yes

String

Log stream ID.

Minimum: 36

Maximum: 36

key_word

Yes

String

A keyword is a word between two adjacent delimiters.

is_iterative

No

Boolean

Whether the log query is iterative. The default value is false, indicating that the log query is not iterative.

Enumeration values:

  • true

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

count

Long

Number of logs.

histogram

String

Histogram result.

isQueryComplete

Boolean

Whether the query is complete.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 8

Maximum: 8

error_msg

String

Error message.

Status code: 500

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 8

Maximum: 8

error_msg

String

Error message.

Example Requests

Querying the log histogram

POST https://{endpoint}/v2/{project_id}/lts/keyword-count

{
  "group_id" : "00330565-5baf-4e0d-bd16-ba0c6b951d9a",
  "stream_id" : "715cda3b-e17f-492a-a6ca-98a1ba16ad8c",
  "end_time" : 1637820813605,
  "start_time" : 1637817213605,
  "key_word" : "test",
  "step_interval" : 6000
}

Example Responses

Status code: 200

The query is successful.

{
  "count" : 1,
  "histogram" : [ {
    "num" : 1,
    "startTime" : 1637821594579,
    "endTime" : 1637821595000
  }, {
    "num" : 0,
    "startTime" : 1637821654000,
    "endTime" : 1637821654579
  } ]
}

Status code: 400

Invalid request. Modify the request based on the description in error_msg before a retry.

{
  "error_code" : "LTS.0601",
  "error_msg" : "must be less than or equal to 86400000"
}

Status Codes

Status Code

Description

200

The query is successful.

400

Invalid request. Modify the request based on the description in error_msg before a retry.

500

InternalServerError. The server has received the request but encountered an internal error.

Error Codes

See Error Codes.