Mengkueri data log dari penyimpanan log di Proyek yang ditentukan.
Deskripsi operasi
Simple Log Service supports scheduled SQL jobs. For details, see Create a scheduled SQL job.
-
The Host in the request syntax consists of the project name and the Simple Log Service endpoint. Specify the project name in the Host.
-
Create and obtain an AccessKey pair. For details, see AccessKey pair.
Create and use a RAM user to make API calls or perform routine O&M. Using an Alibaba Cloud account AccessKey pair grants access to all APIs and poses a high security risk. Ensure the RAM user has the required permissions for Simple Log Service resources. For details, see Create and authorize a RAM user.
-
Obtain the project name, region, and Logstore name for the logs to query. See Manage a project and Manage a Logstore.
-
Simple Log Service imposes limits on log queries. Design appropriate query and analytic statements and set a reasonable time range. See Log query limits and Log analysis limits.
-
Configure indexes before querying logs. See Create indexes.
-
When the number of matching logs varies significantly, the API cannot predict how many calls are needed to retrieve the complete result. Check the
x-log-progressheader in each response to determine whether to repeat the call. Each repeated call consumes the same number of query capacity units (CUs). -
After a log is written to a Logstore, the latency before it becomes queryable through the GetHistograms and GetLogs operations depends on the log type. Simple Log Service classifies logs into two types based on their timestamps:
-
Real-time data: The log timestamp falls within (-180 seconds, 900 seconds] relative to the current server time. For example, if a log is generated at UTC 2014-09-25 12:03:00 and is received by the server at UTC 2014-09-25 12:05:00, the log is classified as real-time data. This is typical in normal scenarios. Real-time data becomes queryable in about 3 seconds.
-
Historical data: The log timestamp falls within [-7 x 86,400 seconds, -180 seconds) relative to the current server time. For example, if a log is generated at UTC 2014-09-25 12:00:00 and is received by the server at UTC 2014-09-25 12:05:00, the log is classified as historical data. This is typical in data backfill scenarios.
-
Simple Log Service calculates the difference between the log time (the __time__ field) and the server receipt time (the __tag__: receive_time field). If the difference falls within (-180 seconds, 900 seconds], the log is real-time data. If the difference falls within [-7 x 86,400 seconds, -180 seconds), the log is historical data.
Simple Log Service provides Java and Python SDK examples for the GetLogs operation. See GetLogs examples for Java and GetLogs examples for Python.
Authorization
The following table describes the authorization information required for this operation. Add this information to the Action element of a RAM access policy statement to grant RAM users or RAM roles the permission to call this operation.
| Action | Resource |
log:GetLogStoreLogs | acs:log:{#regionId}:{#accountId}:project/{#ProjectName}/logstore/{#LogstoreName} |
Coba sekarang
Test
RAM authorization
Sintaks permintaan
GET /logstores/{logstore}?type=log HTTP/1.1
Path Parameters
|
Parameter |
Type |
Required |
Description |
Example |
| logstore |
string |
Yes |
Penyimpanan log yang akan dikueri. |
example-logstore |
Parameter permintaan
|
Parameter |
Type |
Required |
Description |
Example |
| project |
string |
Yes |
Nama Proyek. |
ali-test-project |
| from |
integer |
Yes |
Awal pengatur waktu kueri, berdasarkan waktu log yang ditentukan saat data log ditulis.
Catatan
Untuk menghindari data yang hilang, sesuaikan waktu kueri ke tingkat menit. Jika pengatur waktu ditentukan dalam pernyataan analitik, pengatur waktu tersebut akan diutamakan. Untuk menentukan waktu dalam detik di dalam pernyataan analitik, gunakan fungsi from_unixtime atau fungsi to_unixtime untuk mengonversi format waktu. Contoh:
|
1627268185 |
| to |
integer |
Yes |
Akhir pengatur waktu kueri, berdasarkan waktu log yang ditentukan saat data log ditulis.
Catatan
Untuk menghindari data yang hilang, sesuaikan waktu kueri ke tingkat menit. Jika pengatur waktu ditentukan dalam pernyataan analitik, pengatur waktu tersebut akan diutamakan. Untuk menentukan waktu dalam detik di dalam pernyataan analitik, gunakan fungsi from_unixtime atau fungsi to_unixtime untuk mengonversi format waktu. Contoh:
|
1627269085 |
| query |
string |
No |
Pernyataan pencarian atau pernyataan analitik. Lihat Ikhtisar kueri dan Ikhtisar analisis. Untuk mengaktifkan fitur SQL Eksklusif, tambahkan Catatan
Ketika parameter query berisi pernyataan analitik (pernyataan SQL), parameter |
status: 401 | SELECT remote_addr,COUNT(*) as pv GROUP by remote_addr ORDER by pv desc limit 5 |
| topic |
string |
No |
Topik log. Nilai default: string kosong. Lihat Topik. |
topic |
| line |
integer |
No |
Hanya valid ketika parameter query adalah pernyataan pencarian. Jumlah maksimum log yang akan dikembalikan. Nilai valid: 0 hingga 100. Nilai default: 100. Lihat Melakukan paginasi pada hasil kueri dan analisis. |
100 |
| offset |
integer |
No |
Hanya valid ketika parameter query adalah pernyataan pencarian. Baris awal untuk kueri. Nilai default: 0. Lihat Melakukan paginasi pada hasil kueri dan analisis. |
0 |
| reverse |
boolean |
No |
Apakah akan mengembalikan log dalam urutan menurun berdasarkan stempel waktu, dengan presisi tingkat menit.
Penting
|
false |
| powerSql |
boolean |
No |
Apakah akan mengaktifkan fitur SQL Eksklusif. Lihat Mengaktifkan fitur SQL Eksklusif.
Sebagai alternatif, tambahkan |
false |
Elemen respons
|
Element |
Type |
Description |
Example |
|
array |
The log array. Each element is a log entry. |
||
|
object |
The log array. Each element is a log entry. |
[{'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.100.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}] |
Contoh
Respons sukses
JSONformat
[
{
"test": "test",
"test2": 1
}
]
Kode kesalahan
Lihat Error Codes untuk daftar lengkap.
Catatan rilis
Lihat Release Notes untuk daftar lengkap.