Querying Logs

Function

This API is used to query logs by different dimensions such as cluster, IP address, or application.

URI

POST /v2/{project_id}/als/action?type=querylogs

Table 1 describes the parameters.

Table 1 Parameters

Parameter

Mandatory

Description

project_id

Yes

Project ID obtained from IAM. Generally, a project ID contains 32 characters.

type

Yes

Log API call mode. When the value is querylogs, this API is used to query logs.

Request

Request parameters

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Mandatory

Type

Value Range

Description

Condition

Yes

String

{

"category": "app_log",

"searchKey":

{

"clusterId": "c693fa7c-54cd-11e8-8055-0255ac101e40",

"nameSpace": "",

"appName": "",

"podName": "",

"pathFile": "",

"hostIP":""

},

"keyWord": "",

"startTime": 1538970064983,

"endTime": 1538970364983,

"hideSyslog": 0

}

Condition in JSON format, which must be in the request body during calling.

category

Yes

String

app_log,node_log,custom_log

Log type:

  • app_log: application log

  • node_log: host log

  • custom_log: log in a custom path

searchKey

Yes

JSON

-

Log filter criteria, which vary according to log sources.

clusterId

Yes

String

-

Cloud Container Engine (CCE) cluster ID.

nameSpace

No

String

-

CCE cluster namespace.

appName

No

String

-

Service name.

podName

No

String

-

Container pod name.

pathFile

No

String

-

Log file name.

hostIP

No

String

-

IP address of the VM where logs are located.

keyWord

No

String

-

  1. Enter a keyword between two adjacent delimiters for exact search.

  2. Enter a keyword for fuzzy search. Example: RROR, ERRO?, *ROR*, ERR*, or ER*OR.

  3. Enter a phrase for exact search. Example: Start to refresh alm Statistic.

  4. Enter contents containing AND (&&) or OR (||) for search. Example: query&&logs or query||logs.

Note

Default delimiters:

, '";=()[]{}@&<>/:\n\t\r

startTime

Yes

Long

-

Start time of the query (UTC, in ms).

endTime

Yes

Long

-

End time of the query (UTC, in ms).

hideSyslog

No

Integer

0 or 1

Whether to hide the system log (icagent\kubectl) during the query. 0 (default): Hide. 1: Not hide.

Request headers

Table 3 describes the request headers.

Table 3 Request headers

Name

Mandatory

Description

X-Auth-Token

Yes

User token obtained from IAM.

Content-Type

Yes

Content type, which is application/json.

Example request

Example 1 (Query application logs in a cluster)

/v2/{project_id}/als/action?type=querylogs
{
    "category": "app_log",
    "searchKey":
              {
                "clusterId": "c693fa7c-54cd-11e8-8055-0255ac101e40",
        "nameSpace" : "",
        "appName" : "",
        "podName" : "",
        "pathFile" : "",
        "hostIP" : ""
              },
    "keyWord": "",
    "startTime": 1538970064983,
    "endTime": 1538970364983,
    "hideSyslog": 0
}

Response

Response parameters

Table 4 describes the response parameters.

Table 4 Response parameters

Parameter

Type

Description

errorCode

String

Response code. Example: AOM.0200, which indicates a success response.

errorMessage

String

Response message.

result

JSON object

Metadata, including total number of returned records and results.

total

Integer

Number of returned records.

data

JSON array

Data array.

category

String

Log type.

loghash

String

Hash value of the log source.

clusterId

String

Cloud Container Engine (CCE) cluster ID.

clusterName

String

CCE cluster name.

nameSpace

String

CCE cluster namespace.

podName

String

CCE container pod name.

appName

String

Service name.

serviceID

String

Service ID of an AOM resource.

containerName

String

CCE container name.

logContent

String

Source log data.

pathFile

String

Absolute path of a log file.

hostIP

String

IP address of the VM where log files are located.

hostId

String

ID of a host in a cluster.

hostName

String

Name of the VM where log files are located.

collectTime

String

Log collection time (UTC time, in ms).

lineNum

String

Sequence number of a log line.

logContentSize

String

Size of a single-line log.

Example response

{
 "errorCode":"AOM.0200",
 "errorMessage":"Query data success",
 "result":"{\"total\":5000,
            \"data\":[{\"category\":\"app\",
            \"loghash\":\"496b2070d40a83c17f2625401af8a50aadc316f216771fbe38b94d31feaa30eb\",
            \"clusterId\":\"c693fa7c-54cd-11e8-8055-0255ac101e40\",
            \"clusterName\":\"aomdemo\",
            \"nameSpace\":\"default\",
            \"podName\":\"als0712-7c4875f884-q5wwp\",
            \"appName\":\"als0712\",
            \"serviceID\":\"\",
            \"containerName\":\"container-0\",
            \"logContent\":\"warn:2018/10/09 06:57:01 helloworld.go:108: the main process is running now.\\n\",
            \"pathFile\":\"/var/paas/sys/log/apm/debug_erro.trace\",
            \"hostIP\":\"192.168.0.133\",
            \"hostId\":\"c11c7211-5a0b-4925-bef4-d078661299b0\",
            \"hostName\":\"192.168.0.133\",
            \"collectTime\":\"1539068233983\",
            \"lineNum\":\"15390682339830002\",
            \"logContentSize\":\"77\"
                      }]
            }"
}

Status Code

  • Success response

    Table 5 describes the status code.

    Table 5 Status code

    Status Code

    Message

    Description

    200

    OK

    The request has succeeded.

  • Error response

    Table 6 describes the status codes. For more information, see Status Codes.

    Table 6 Status codes

    Status Code

    Message

    Description

    400

    Bad Request

    The request is invalid.

    The client should not repeat the request without modifications.

    401

    Unauthorized

    The authorization information provided by the client is incorrect or invalid.

    403

    Forbidden

    The request is rejected.

    The server has received the request and understood it, but the server is refusing to respond to it. The client should not repeat the request without modifications.

    500

    Internal Server Error

    The server is able to receive the request but unable to understand the request.

    503

    Service Unavailable

    The requested service is invalid.

    The client should not repeat the request without modifications.

Error Code

Table 7 Error codes

Error Code

Message

Solution

AOM.0200

Data queried successfully.

-

AOM.0201

{XXX} is invalid.

Note

XXX indicates a specific parameter.

Check whether the parameter meets requirements.

AOM.0203

No logs found.

Check whether the parameter meets requirements.