All Products
Search
Document Center

Simple Log Service:GetHistograms

Last Updated:Oct 26, 2023

Queries the distribution of logs that meet the specified search conditions in a Logstore. The response includes the number of logs that are generated within a specific time range.

Usage notes

  • Host consists of a project name and a Log Service endpoint. You must specify a project in Host.
  • 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 Log Service is a high-risk operation. We recommend that you use a 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 Log Service resources. For more information, see Create a RAM user and authorize the RAM user to access Log Service.

  • 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 a project and Manage a Logstore.
  • Indexes are configured before you query logs. For more information, see Create indexes.
  • You can use the query parameter to specify only a search statement. You cannot use the parameter to specify an analytic statement. For more information about the syntax and limits of search statements, see Log search overview.
  • The time range is evenly divided into subintervals in the responses. If the time range that is specified in the request remains unchanged, the subintervals in the responses also remain unchanged.
  • If the number of logs in a Logstore significantly changes, Log Service cannot predict the number of times that you must call this operation to obtain the complete result. In this case, you must check the value of the progress parameter in the response of each request and determine whether to call this operation one more time to obtain the complete result. Each time you call this operation, the same number of charge units (CUs) are consumed.
  • After a log is written to a Logstore, you can call the GetHistograms or GetLogs operation to query the log after a short latency. The latency of a query varies based on the type of the log. Log Service classifies logs into the following types based on the log time:
    • Real-time data: The difference between the time record in a log and the current time on Log Service is within the interval (-180 seconds,900 seconds]. For example, if a log was generated at 12:03:00, September 25, 2014 (UTC) and Log Service received the log at 12:05:00, September 25, 2014 (UTC), Log Service processes the log as real-time data. After real-time data is written to a Logstore, the data can be queried with a maximum latency of 3 seconds.
    • Historical data: The difference between the time record in a log and the current time on Log Service is within the interval [-604,800 seconds,-180 seconds). For example, if a log was generated at 12:00:00, September 25, 2014 (UTC) and Log Service received the log at 12:05:00, September 25, 2014 (UTC), Log Service processes the log as historical data. This type of log is usually generated in data backfill scenarios.

      After real-time data is written to a Logstore, the data can be queried with a maximum latency of 3 seconds. For 99.9% of queries, the latency is no more than 1 second.

Note Log Service calculates the difference between the log time that is specified by the __time__ field and the receiving time that is specified by the __tag__:__receive_time__ field for each log. The receiving time indicates the time at which Log Service receives the log. If the difference is within the interval (-180 seconds,900 seconds], Log Service processes the log as real-time data. If the difference is within the interval [-604,800 seconds,-180 seconds), Log Service processes the log as historical data.

Authentication resources

The following table describes the authorization information that is required for this operation. You can add the information to the Action element of a RAM policy statement to grant a RAM user or a RAM role the permissions to call this operation.

Action

Resource

log:GetLogStoreHistogramacs:log:{#regionId}:{#accountId}:project/{#ProjectName}/logstore/{#LogstoreName}

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request headers

This operation uses only common request headers. For more information, see Common request headers.

Request syntax

GET /logstores/{logstore}/index?type=histogram HTTP/1.1

Request parameters

ParameterTypePositionRequiredExampleDescription
projectStringHostYesali-test-project

The name of the project.

logstoreStringPathYestest-logstore

The name of the Logstore.

fromLongQueryYes1409529600

The start time of the subinterval. The value is a UNIX timestamp representing the number of seconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

toLongQueryYes1409569200

The end time of the subinterval. The value is a UNIX timestamp representing the number of seconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

topicStringQueryNotopic

The topic of the logs.

queryStringQueryNowith_pack_meta

The search statement. Only search statements are supported. Analytic statements are not supported. For more information about the syntax and limits of search statements, see Log search overview.

Response parameters

ParameterTypeExampleDescription
ServerStringnginx

The name of the server.

Content-TypeStringapplication/json

The type of the response body.

Content-LengthString0

The length of the response body.

ConnectionStringclose

Indicates whether the connection is persistent. Valid values:

  • close: The connection is non-persistent. A new TCP connection is established for each HTTP request.
  • keep-alive: The connection is persistent. After a TCP connection is established, the connection remains open, and no more time or bandwidth is consumed to establish new connections.
DateStringSun, 27 May 2018 08:25:04 GMT

The time.

x-log-requestidString5B0A6B60BB6EE39764D458B5

The request ID.

Array
fromLong1409529600

The start time of the subinterval. The value is a UNIX timestamp representing the number of seconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

The time range that is specified in this operation is a left-closed, right-open interval. The interval includes the start time specified by the from parameter, but does not include the end time specified by the to parameter. If you specify the same value for the from and to parameters, the interval is invalid, and an error message is returned.

toLong1409569200

The end time of the subinterval. The value is a UNIX timestamp representing the number of seconds that have elapsed since the epoch time January 1, 1970, 00:00:00 UTC.

The time range that is specified in this operation is a left-closed, right-open interval. The interval includes the start time specified by the from parameter, but does not include the end time specified by the to parameter. If you specify the same value for the from and to parameters, the interval is invalid, and an error message is returned.

countLong2

The number of logs that are generated within the subinterval.

progressStringComplete

Indicates whether the query result in the subinterval is complete. Valid values:

Complete: The query is successful, and the complete result is returned.

Incomplete: The query is successful, but the query result is incomplete. To obtain the complete result, you must repeat the request.

Examples

Sample requests

GET /logstores/test-logstore/index?type=histogram?from=1409529600&to=1409569200&topic=topic&query=with_pack_meta HTTP/1.1
Host:ali-test-project.cn-hangzhou.log.aliyuncs.com
Content-Type:application/json

Sample success responses

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "from" : 1409529600,
  "to" : 1409569200,
  "count" : 2,
  "progress" : "Complete"
}

Error codes

For a list of error codes, see Service error codes.

HTTP status code

Error code

Error message

Description

404

ProjectNotExist

Project does not exist.

The specified project does not exist.

404

LogStoreNotExist

Logstore does not exist.

The specified Logstore does not exist.

400

InvalidTimeRange

request time range is invalid.

The specified time range is invalid.

400

InvalidQueryString

query string is invalid.

The specified search statement in the request is invalid.

500

InternalServerError

Specified Server Error Message.

An internal server error has occurred.

For more information, see Common error codes.