全部产品
Search
文档中心

日志服务:get_histograms

更新时间:Oct 26, 2023

调用CLI命令查询指定Logstore中满足查询语法条件的日志分布情况,返回结果显示某时间区间中的日志条数(数量)。

命令格式

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>]

命令参数

该命令的必选和特有参数描述如下。
参数名称数值类型是否必选示例值描述
--requestJSON Objectfile://./gethistograms.json查询日志的配置文件路径。
关于该命令的全局参数,请参见全局参数

命令示例

该示例中,先给出本次示例的原始日志样例,然后编写gethistograms.json文件,用于查询指定区间内request_method为PUT且status状态为200的日志数量分布情况。

  1. 原始日志样例
    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
  2. 创建gethistograms.json文件,用于查询15分钟内request_method为PUT且status状态为200的日志数量分布情况。其内容示例如下:
    {
    "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"
    }
    各参数说明如下:
    参数名称描述
    topic日志主题。
    logstoreLogstore名称。
    projectProject名称。
    toTime查询结束时间点。例如2023-03-03 14:30:41。
    query查询语句。仅支持查询语句,不支持分析语句。关于查询语句的详细语法,请参见查询语法
    fromTime查询开始时间点。例如2023-03-03 14:15:41。
  3. 执行命令示例如下:
    aliyunlog log get_histograms --request="file://./gethistograms.json" --format-output=json
    15分钟内各区间中满足条件的日志数量分布情况,返回结果如下:
    [
      {
        "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
      }
    ]

相关文档

  • 日志服务提供Java SDK的GetHistograms查询使用示例。更多信息,请参见使用GetHistograms查询日志分布数量
  • 在调用API接口过程中,若服务端返回结果中包含错误信息,则表示调用API接口失败。您可以参考API错误码对照表查找对应的解决方法。更多信息,请参见API错误处理对照表
  • 阿里云OpenAPI开发者门户提供调试、SDK、示例和配套文档。通过OpenAPI,您无需手动封装请求和签名操作,就可以快速对日志服务API进行调试。更多信息,请参见OpenAPI开发者门户
  • 关于该API接口的详细信息,请参见GetHistograms