- What's New
- Function Overview
- Service Overview
- Billing
- Getting Started
-
User Guide
- Granting LTS Permissions to IAM Users
- Purchasing LTS Resource Packages
- Log Management
-
Log Ingestion
- Overview
-
Using ICAgent to Collect Logs
- Overview
- Installing ICAgent (Intra-Region Hosts)
- Installing ICAgent (Extra-Region Hosts)
- Managing ICAgent
- Managing Host Groups
- Ingesting BMS Text Logs to LTS
- Ingesting CCE Application Logs to LTS
- Ingesting ECS Text Logs to LTS
- Ingesting ServiceStage Containerized Application Logs to LTS
- Ingesting ServiceStage Cloud Host Logs to LTS
- Ingesting Self-Built Kubernetes Application Logs to LTS
- Setting ICAgent Structuring Parsing Rules
-
Ingesting Cloud Service Logs to LTS
- Overview
- Ingesting AOM Logs to LTS
- Ingesting APIG Logs to LTS
- Ingesting CBH Logs to LTS
- Ingesting CFW Logs to LTS
- Ingesting CTS Logs to LTS
- Ingesting DDS Logs to LTS
- Ingesting DMS for Kafka Logs to LTS
- Ingesting DRS Logs to LTS
- Ingesting GaussDB(DWS) Logs to LTS
- Ingesting ELB Logs to LTS
- Ingesting Enterprise Router Logs to LTS
- Ingesting FunctionGraph Logs to LTS
- Ingesting GaussDB Logs to LTS
- Ingesting GES Logs to LTS
- Ingesting TaurusDB Logs to LTS
- Ingesting GeminiDB Logs to LTS
- Ingesting GeminiDB Mongo Logs to LTS
- Ingesting GeminiDB Cassandra Logs to LTS
- Ingesting IoTDA Logs to LTS
- Ingesting ModelArts Logs to LTS
- Ingesting MRS Logs to LTS
- Ingesting RDS for MySQL Logs to LTS
- Ingesting RDS for PostgreSQL Logs to LTS
- Ingesting RDS for SQL Server Logs to LTS
- Ingesting ROMA Connect Logs to LTS
- Ingesting SMN Logs to LTS
- Ingesting SecMaster Logs to LTS
- Ingesting OBS Files to LTS (Beta)
- Ingesting VPC Logs to LTS
- Ingesting WAF Logs to LTS
- Using APIs to Ingest Logs to LTS
- Ingesting Logs to LTS Across IAM Accounts
- Using Kafka to Report Logs to LTS
- Using Flume to Report Logs to LTS
- Log Search and Analysis
-
Log Visualization
- Overview
- Visualizing Logs in Statistical Charts
-
Visualizing Logs in Dashboards
- Creating a Dashboard
- Adding a Dashboard Filter
-
Dashboard Templates
- APIG Dashboard Templates
- CCE Dashboard Templates
- CDN Dashboard Templates
- CFW Dashboard Templates
- CSE Dashboard Templates
- DCS Dashboard Template
- DDS Dashboard Template
- DMS Dashboard Template
- DSL Dashboard Template
- ER Dashboard Template
- METRIC Dashboard Template
- Nginx Dashboard Templates
- VPC Dashboard Template
- WAF Dashboard Templates
- Log Alarms
- Log Transfer
- Log Processing
- Configuration Center
- Querying Real-Time LTS Traces
-
Best Practices
- Overview
-
Log Ingestion
- Collecting Logs from Third-Party Cloud Vendors, Internet Data Centers, and Other Huawei Cloud Regions to LTS
- Collecting Kubernetes Logs from Third-Party Clouds, IDCs, and Other Huawei Cloud Regions to LTS
- Collecting Syslog Aggregation Server Logs to LTS
- Importing Logs of Self-built ELK to LTS
- Using Flume to Report Logs to LTS
- Collecting Zabbix Data Through ECS Log Ingestion
- Collecting Logs from Multiple Channels to LTS
- Log Search and Analysis
- Log Transfer
- Billing
- Developer Guide
-
API Reference
- Before You Start
- API Overview
- Calling APIs
- API Calling Examples
- Examples
-
APIs
- Host Group Management
- Log Group Management
- Log Stream Management
- Log Management
- Log Ingestion
- Log Transfer
- Log Collection Beyond Free Quota
- Cloud Log Structuring
- Container Log Ingestion from AOM to LTS
- Alarm Topics
- Message Template Management
- SQL Alarm Rules
- Keyword Alarm Rules
- Alarm List
- Tag Management
- Dashboard Management
- Log Charts
- Quick Search
- Multi-Account Log Aggregation
- Permissions Policies and Supported Actions
- Appendix
- SDK Reference
-
FAQs
- Overview
- Consultation
- Log Management
-
Host Management
- What Do I Do If ICAgent Installation Fails in Windows and the Message "SERVICE STOP" Is Displayed?
- What Do I Do If ICAgent Upgrade Fails on the LTS Console?
- What Do I Do If I Could Not Query New Logs on LTS?
- What Do I Do If ICAgent Restarts Repeatedly After Being Installed?
- What Do I Do If ICAgent Is Displayed as Offline on the LTS Console After Installation?
- What Do I Do If I Do Not See a Host with ICAgent Installed on the LTS Console?
- How Do I Create a VPC Endpoint on the VPCEP Console?
- How Do I Obtain an AK/SK Pair?
- How Do I Install ICAgent by Creating an Agency?
-
Log Ingestion
- What Do I Do If LTS Cannot Collect Logs After I Configure Host Log Ingestion?
- Will LTS Stop Collecting Logs After the Free Quota Is Used Up If I Disable "Continue to Collect Logs When the Free Quota Is Exceeded" in AOM?
- What Do I Do If the CPU Usage Is High When ICAgent Is Collecting Logs?
- What Kinds of Logs and Files Does LTS Collect?
- How Do I Disable the Function of Collecting CCE Standard Output Logs to AOM on the LTS Console?
- What Log Rotation Scheme Should I Use for ICAgent to Collect Logs?
- Does LTS Use the Log4j Plug-in to Report Logs?
- How Long Does It Take to Generate Logs After Configuring Log Ingestion?
- What Do I Do If LTS Cannot Collect Logs After I Configure Log Ingestion with ICAgent?
- Log Search and Analysis
-
Log Transfer
- Does LTS Delete Logs That Have Been Transferred to OBS Buckets?
- What Are the Common Causes of LTS Log Transfer Abnormalities?
- How Do I Transfer CTS Logs to an OBS Bucket?
- What Do I Do If I Cannot View Historical Data in an OBS Bucket After Transferring Data from LTS to OBS?
- What Do I Do If I Cannot Find a New Partition in a DLI Table After Logs Are Transferred to DLI?
-
More Documents
- User Guide (ME-Abu Dhabi Region)
- API Reference (ME-Abu Dhabi Region)
- User Guide(Paris Regions)
- API Reference(Paris Regions)
- User Guide (Kuala Lumpur Region)
- API Reference (Kuala Lumpur Region)
- User Guide (Ankara Region)
-
API Reference (Ankara Region)
- Before You Start
- Calling APIs
- API Calling Examples
- APIs
- Permissions and Supported Actions
- Appendix
- Change History
- Videos
- General Reference
Copied.
Overview
Structured Query Language (SQL) is a programming language used to control database access and manage data in databases. LTS SQL provides statements for querying structured data in log streams. In this document, SQL refers to LTS SQL.
SQL consists of commands and functions that are used to manage databases and database objects. When using this language, comply with the rules for using expressions and texts. In addition to SQL syntax reference, this document also provides information about expressions, functions, and operators. Basic SQL query statements are as follows.
Currently, this function is available to all users in regions CN South-Guangzhou, CN North-Beijing4, CN East-Shanghai1, CN East-Shanghai2, CN-Hong Kong, CN Southwest-Guiyang1, AP-Singapore, and CN North-Beijing1. It is also available to whitelisted users in regions CN South-Shenzhen, AP-Bangkok, ME-Riyadh, and AP-Jakarta.
Syntax
SELECT [ ALL | DISTINCT ] { * | exprs } FROM { <subquery>} [ WHERE where_condition ] [ GROUP BY [ col_name_list ] [ HAVING expr ] [ ORDER BY expr [ ASC | DESC ], expr [ ASC | DESC ], ... ] [ LIMIT limit ] [ OFFSET offset ]
Data Types
In the SQL syntax, characters must be enclosed in single quotation marks ('). Fields or table names are not enclosed or are enclosed with double quotation marks ("). For example, 'msg' indicates the character string msg, and msg or "msg" indicates the structured msg field.
Query Statements
Statement |
Description |
Example |
---|---|---|
DISTINCT |
Only distinct values are returned. |
SELECT DISTINCT visitCount |
FROM |
Indicates the source data set of the queried data. It can be the structured data of the current log stream or a subset of this data. If FROM is not specified, the structured data of the current log stream is queried by default. If the data source to be queried is a subset, you need to compile a subquery statement. |
SELECT visitCount |
WHERE |
Specifies the filter criteria. Arithmetic operators, relational operators, and logical operators are supported. You can enter the filtering condition in where_condition. |
SELECT visitCount WHERE visitCount > 0 |
GROUP BY |
Specifies the grouping field. Single-field grouping and multi-field grouping are supported. You can enter the structured field list in col_name_list. |
SELECT host, count(*) AS pv WHERE visitCount > 0 GROUP BY host |
HAVING |
Used only with GROUP BY. This statement specifies the structured field used to filter the GROUP BY results. |
SELECT host, count(*) AS pv GROUP BY host HAVING pv > 10 |
ORDER BY |
Fields that follow must be used for GROUP BY. The query results of GROUP BY can be sorted by any structured field. |
SELECT host, count(*) AS pv GROUP BY host ORDER BY pv |
ASC/DESC |
ASC (default) sorts from the lowest value to the highest value. DESC sorts from the highest value to the lowest value. |
SELECT host, count(*) AS pv GROUP BY host ORDER BY pv DESC |
LIMIT |
Limits the number of structured logs returned in the query result. A maximum of 100,000 structured logs can be returned for each query. If the LIMIT statement is not used, the latest 100 records in the query result are returned by default. |
SELECT host LIMIT 100 |
Examples
Query Requirement |
Query Statement |
---|---|
Standard query |
SELECT "field" WHERE "field" = 'value' |
Number of rows |
SELECT count(*) |
Column alias |
SELECT count(*) AS "pv" |
Deduplication |
SELECT DISTINCT("field") |
Pagination |
SELECT "field" LIMIT 100 |
Sorting |
SELECT "__time" ORDER BY "__time" |
Grouping |
SELECT "field" GROUP BY "field" |
Statistics by group |
SELECT "field",count(*) GROUP BY "field" |
Fuzzy search |
SELECT "field" LIKE 'value%' |
Sum |
SELECT sum("field") |
Maximum value |
SELECT max("field") |
Minimum value |
SELECT min("field") |
Average value |
SELECT avg("field") |
SQL nested subquery |
SELECT sum(pv) FROM (SELECT "field",count(*) AS "pv" GROUP BY "field") |
HAVING clause filtering |
SELECT "field",count(*) AS "pv" GROUP BY "field" HAVING "pv" > 10 |
Query containing GET and POST requests |
SELECT * WHERE "request_method" IN ('GET', 'POST') |
Query without GET and POST requests |
SELECT * WHERE "request_method" NOT IN ('GET', 'POST') |
Logs of non-GET requests |
SELECT * WHERE "request_method" != 'GET' |
Logs of successful GET request with the 200 status code and request time is less than 60 seconds |
SELECT * WHERE "request_method" = 'GET' AND "request_time" < 60 |
Logs of requests whose time is greater than or equal to 60 seconds and less than 200 seconds |
SELECT * WHERE "request_ time" >=60 and "request_time" < 200 |
Logs of GET or POST requests |
SELECT * WHERE "request_method" = 'GET' OR "request_method" = 'POST' |
The following reference statements contain all basic query syntax and are constructed based on structured logs of Elastic Load Balance (ELB).
SELECT url AS Url, host AS Host, failure_rate AS FailureRate, CONCAT(CAST(access_count AS varchar), ' times') AS "All", CONCAT(CAST(rsp_200_count AS varchar), ' times') AS "COUNT_200" FROM ( SELECT CONCAT(host, CASE WHEN STRPOS(router_request_uri, '?') = 0 THEN router_request_uri ELSE SUBSTR(router_request_uri, 1, 1) END) AS url, host,count(1) AS access_count, SUM(CASE WHEN status = 200 THEN 1 ELSE 0 END) AS "rsp_200_count", (CASE WHEN COUNT(1) < 30 THEN 0 ELSE round(SUM(CASE WHEN status >= 400 THEN 1 ELSE 0 END) * 100.0 / COUNT(1), 2) END) AS failure_rate WHERE host NOT IN ('monitor-new.olayc.cn') GROUP BY host,router_request_uri HAVING router_request_uri NOT IN ('/robots.txt', '/null', '/undefined') ) ORDER BY FailureRate DESC LIMIT 100
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