Query log distribution (GetHistograms)

Updated at:

Run CLI commands to query the distribution and total count of logs within a specified time range.

Prerequisites

Before you begin, make sure that:

  • Simple Log Service (SLS) is activated. For more information, see Get started with SLS.

  • The SLS CLI is installed and configured. For more information, see Install and configure the new SLS CLI.

  • An SLS project and Logstore are created, and indexes are configured. For more information, see Create a project, Create a Logstore, and Create an index.

Command syntax

aliyun sls get-histograms --project=<value> --logstore=<value> --from=<value> --to=<value> [--query=<value>]

Parameters

The following table describes the required and command-specific parameters.

ParameterTypeRequiredExampleDescription
--projectStringYesaliyun-test-projectThe name of the project.
--logstoreStringYesaliyun-test-logstoreThe name of the Logstore.
--fromIntegerYes1740000000The start time of the query. Specify a Unix timestamp in seconds.
--toIntegerYes1740003600The end time of the query. Specify a Unix timestamp in seconds.
--queryStringNo*The query expression.

For information about global parameters, see Global parameters.

Command examples

Query log distribution

  • Command example

Query the distribution of logs that contain the keyword "error".

aliyun sls get-histograms --project="aliyun-test-project" --logstore="aliyun-test-logstore" \
  --from 1740000000 --to 1740003600 --query 'error'
  • Response example

{
  "total": 1250,
  "histograms": [
    {
      "from": 1740000000,
      "to": 1740000600,
      "count": 200
    },
    {
      "from": 1740000600,
      "to": 1740001200,
      "count": 180
    }
  ]
}

Query the distribution of all logs

  • Command example

Query the distribution of all logs within a specified time range.

aliyun sls get-histograms --project="aliyun-test-project" --logstore="aliyun-test-logstore" \
  --from 1740000000 --to 1740003600
  • Response example

{
  "total": 5000,
  "histograms": [
    {
      "from": 1740000000,
      "to": 1740000600,
      "count": 800
    },
    {
      "from": 1740000600,
      "to": 1740001200,
      "count": 750
    }
  ]
}

References

  • If the response returned by the server contains an error message when you call an API operation, the call has failed. You can refer to the API error code table to find the corresponding solution. For more information, see PutLogs.

  • The Alibaba Cloud OpenAPI developer portal provides debugging tools, SDKs, examples, and supporting documentation. With OpenAPI, you can quickly debug Simple Log Service API operations without manually constructing requests or signing them. For more information, see the OpenAPI developer portal.

API reference

GetHistograms