Query the number of distributed logs
Calls the GetHistograms operation to query the distribution of logs that match specified conditions in a Logstore.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameters
def get_histograms(self, request):
Request parameters
|
Name |
Type |
Required |
Description |
|
request |
GetHistogramsRequest |
Yes |
The request parameters for the GetHistograms operation. Specifies conditions for querying log distribution in a Logstore. |
GetHistogramsRequest parameters:
|
Name |
Type |
Required |
Description |
|
project |
String |
Yes |
Project name: The name of the project. A project is the basic resource management unit in Simple Log Service. It is used to isolate resources and control access for different users. For more information, see Manage projects. |
|
logstore |
String |
Yes |
Logstore name: The name of the Logstore. A Logstore is a unit for collecting, storing, and querying log data in Simple Log Service. For more information, see Manage Logstores. |
|
fromTime |
int |
Yes |
The start time of the subinterval. The value is a UNIX timestamp. |
|
toTime |
int |
Yes |
The end time of the subinterval. The value is a UNIX timestamp. |
|
topic |
String |
No |
The topic of logs. The default value is an empty string. For more information, see Log topics. |
|
query |
String |
No |
The query statement. For more information, see Query and analytic statements. Note
Only query statements are supported. Analytic statements are not supported. |
Response parameters
For details about response parameters, see GetHistograms.
Sample code
from aliyun.log import LogClient, GetHistogramsRequest
import os
# This example shows how to obtain an AccessKey ID and an AccessKey secret from environment variables.
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# The endpoint of Simple Log Service.
endpoint = "cn-hangzhou.log.aliyuncs.com"
client = LogClient(endpoint, access_key_id, access_key_secret)
def main():
project = "proj-test-1"
logstore = "logstore-1"
fromTime = 1728973609
toTime = 1728973612
# Instantiate the GetHistogramsRequest class.
request = GetHistogramsRequest(project, logstore, fromTime, toTime)
# Query the number of distributed logs.
response = client.get_histograms(request)
response.log_print()
if __name__ == '__main__':
main()
Sample response
References
-
APIs for querying log data:
-
More sample code is available in the Alibaba Cloud Simple Log Service SDK for Python GitHub repository.