get_project_logs
Queries logs in a project by running a project-level SQL statement.
Usage notes
Before you run this CLI command, note the following:
Simple Log Service CLI is installed and configured. For more information, see Install the CLI and Configure SLS CLI.
A project and a logstore are created in Simple Log Service, and logs are collected. For more information, see Manage projects, Create a basic LogStore, and Data collection.
An AccessKey pair is created and obtained. For more information, see AccessKey pair.
The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in Simple Log Service is a high-risk operation. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. Make sure that the RAM user has the management permissions on Simple Log Service resources. For more information, see Create a RAM user and grant permissions.
The information that is required to query logs is obtained. The information includes the name of the project to which the logs belong, the region of the project, and the name of the logstore to which the logs belong. For more information, see Manage projects and Manage a logstore.
Limits are imposed when you use Simple Log Service to query logs. We recommend that you specify query statements and query time ranges based on the limits. For more information, see Log search overview and Log analysis overview.
Indexes are created before you query logs. For more information, see Create indexes.
Command syntax
aliyunlog log get_project_logs --request=<value> [--access-id=<value>] [--access-key=<value>] [--sts-token=<value>] [--region-endpoint=<value>] [--client-name=<value>] [--jmes-filter=<value>] [--format-output=<value>] [--decode-output=<value>] [--profile=<value>]
Command parameters
The following table describes the required and specific parameters of this command.
|
Parameter Name |
Numeric types |
Required |
Example |
Description |
|
--request |
String |
Yes |
file://./get_project_logs_config.json |
Path to the log query configuration file. Before you run this command, create the file and specify the project name, query and analytic statement, and other details. You can create the file as described in the command examples.
|
For more information about the global parameters for this command, see Global parameters.
Command examples
-
Create a file named get_project_logs_config.json to specify the project, query statement, and other information. The query statement is used to query the number of page views (PVs) every 10 minutes within an hour. In this example, ali-test-project is the project name, nginx-moni is the Logstore name, and query specifies a standard SQL query statement. The following sample code shows the content of the file:
{ "project": "ali-test-project", "query": "select date_format(__time__-__time__%600, '%H:%i:%s') as time, COUNT(*) as pv from \"nginx-moni\" where __time__ > 1683252000 and __time__ < 1683255600 group by time order by time", "power_sql": false }NoteIf a Logstore name contains special characters such as hyphens (
-), enclose the name in double quotation marks (") in the FROM clause of the SQL statement. Because thequeryvalue is a JSON string, escape the double quotation marks with a backslash (\). In the preceding example, the Logstore namenginx-moniis written as\"nginx-moni\"in the JSON configuration file, which corresponds toFROM "nginx-moni"in the SQL statement. -
Query the distribution of the number of logs every 10 minutes within one hour in the destination project.
-
Sample command
aliyunlog log get_project_logs --request="file://./get_project_logs_config.json" --format-output=json,no_escape -
Sample response
{ "data": [ { "__source__": "", "__time__": "1", "pv": "110", "time": "09:30:00" } ], "meta": { "aggQuery": "select date_format(__time__-__time__%600, '%H:%i:%s') as time, COUNT(*) as pv from gs-api where __time__ > 1718933444 and __time__ < 1718933864 group by time order by time", "count": 1, "cpuCores": 26, "cpuSec": 0.076, "elapsedMillisecond": 29, "hasSQL": true, "mode": 0, "processedRows": 110, "progress": "Complete", "whereQuery": "" } }
-
References
In addition to its native SDK, SLS also supports the common Alibaba Cloud SDKs. For more information, see Log Service_SDKcenter-Alibaba CloudOpenAPIDeveloper Portal.
-
For more information about this API operation, see GetProjectLogs.