Queries the distribution of logs that match specified conditions in a Logstore and returns the log count within each time interval.
Command syntax
aliyunlog log get_histograms --request=<value> [--access-id=<value>] [--access-key=<value>] [--sts-token=<value>] [--region-endpoint=<value>] [--client-name=<value>] [--jmes-filter=<value>] [--format-output=<value>] [--decode-output=<value>]
Command parameters
Required parameters for this command:
|
Parameter |
Type |
Required |
Example |
Description |
|
--request |
JSON Object |
Yes |
file://./gethistograms.json |
Path to the configuration file that contains log query parameters. |
For more information about the global parameters of this command, see Global parameters.
Sample command
This example uses a gethistograms.json file to query the distribution of logs where request_method is PUT and status is 200 within a specified interval.
-
Sample raw log:
body_bytes_sent:1750 host:www.example.com http_referer:www.example.com http_user_agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; it-it) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27 http_x_forwarded_for:203.0.103.10 remote_addr:203.0.103.10 remote_user:p288 request_length:13741 request_method:GET request_time:71 request_uri:/request/path-1/file-1 status:200 time_local:11/Aug/2021:06:52:27 upstream_response_time:0.66 -
Create a gethistograms.json file to query logs where request_method is PUT and status is 200 within the previous 15 minutes:
{ "topic": "", "logstore": "logstore-a", "project": "aliyun-test-project", "toTime": "2023-03-03 14:30:41", "query": "request_method:PUT and status:200", "fromTime": "2023-03-03 14:15:41" }Parameters:
Parameter
Description
topic
The log topic.
logstore
The Logstore name.
project
The project name.
toTime
End of the query time range. Example: 2023-03-03 14:30:41.
query
The search statement. Only
search statementsare supported.Analytic statementsare not supported. For more information, see Search syntax and functions.fromTime
Start of the query time range. Example: 2023-03-03 14:15:41.
-
Run the command:
aliyunlog log get_histograms --request="file://./gethistograms.json" --format-output=jsonSample response:
[ { "count": 18, "from": 1677824141, "progress": "Complete", "to": 1677824160 }, { "count": 37, "from": 1677824160, "progress": "Complete", "to": 1677824190 }, ...... { "count": 30, "from": 1677825000, "progress": "Complete", "to": 1677825030 }, { "count": 0, "from": 1677825030, "progress": "Complete", "to": 1677825041 } ]
References
-
The Simple Log Service documentation provides examples on how to call the GetHistograms operation by using Simple Log Service SDK for Java. For more information, see Use GetHistograms to query the distribution of logs.
In addition to its native SDK, SLS also supports the common Alibaba Cloud SDKs. For more information, see Simple Log Service_SDK Center_Alibaba Cloud OpenAPI Explorer.
-
For more information about the API operation, see GetHistograms.