--- title: "获取节点使用情况" date: 2026-02-02 lastmod: 2026-02-02 description: "获取集群中节点的使用情况统计,包括 REST API 调用统计和聚合使用统计" tags: ["集群管理", "节点统计", "使用监控"] summary: "获取集群中各个节点的使用情况统计信息,特别是 REST API 的调用统计和聚合器使用统计。 API # GET /_cluster/nodes/usage GET /_nodes/usage GET /_nodes/{nodeId}/usage GET /_nodes/usage/{metric} GET /_nodes/{nodeId}/usage/{metric} API 的作用 # 该 API 用于获取集群中各个节点的使用情况统计信息,可以返回: 指标 描述 rest_actions REST API 调用统计(每个 REST 端点被调用的次数) aggregations 聚合器使用统计 这对于监控和调试非常有用,可以帮助开发者了解各个节点的 API 使用情况和性能指标。 API 的参数 # 路由参数 # 参数 类型 是否必填 默认值 描述 {nodeId} 字符串 否 所有节点 指定要获取使用情况的节点。可以是节点 ID、节点名称,或逗号分隔的列表。特殊值:_local 表示当前连接的节点 {metric} 字符串 否 _all 指定要获取的指标类型。可选值:_all、rest_actions Query String 参数 # 参数 类型 是否必填 默认值 描述 timeout 时间值 否 默认超时 显式设置操作的超时时间 可用的指标(metrics) # 指标值 描述 _all 所有指标(包括 rest_actions 和 aggregations) rest_actions REST API 调用统计 参数说明 # metric 参数默认值:_all 当 metric 为 _all 时,会同时启用 rest_actions 和 aggregations 不能同时使用 _all 和具体的指标 示例 # 获取所有节点的所有使用情况统计 # GET /_cluster/nodes/usage 或" --- 获取集群中各个节点的使用情况统计信息,特别是 REST API 的调用统计和聚合器使用统计。 ## API ``` GET /_cluster/nodes/usage GET /_nodes/usage GET /_nodes/{nodeId}/usage GET /_nodes/usage/{metric} GET /_nodes/{nodeId}/usage/{metric} ``` ## API 的作用 该 API 用于获取集群中各个节点的使用情况统计信息,可以返回: | 指标 | 描述 | |------|------| | `rest_actions` | REST API 调用统计(每个 REST 端点被调用的次数) | | `aggregations` | 聚合器使用统计 | 这对于监控和调试非常有用,可以帮助开发者了解各个节点的 API 使用情况和性能指标。 ## API 的参数 ### 路由参数 | 参数 | 类型 | 是否必填 | 默认值 | 描述 | |------|------|----------|--------|------| | `{nodeId}` | 字符串 | 否 | 所有节点 | 指定要获取使用情况的节点。可以是节点 ID、节点名称,或逗号分隔的列表。特殊值:`_local` 表示当前连接的节点 | | `{metric}` | 字符串 | 否 | `_all` | 指定要获取的指标类型。可选值:`_all`、`rest_actions` | ### Query String 参数 | 参数 | 类型 | 是否必填 | 默认值 | 描述 | |------|------|----------|--------|------| | `timeout` | 时间值 | 否 | 默认超时 | 显式设置操作的超时时间 | ## 可用的指标(metrics) | 指标值 | 描述 | |--------|------| | `_all` | 所有指标(包括 rest_actions 和 aggregations) | | `rest_actions` | REST API 调用统计 | ## 参数说明 1. **metric 参数默认值**:`_all` 2. 当 metric 为 `_all` 时,会同时启用 rest_actions 和 aggregations 3. 不能同时使用 `_all` 和具体的指标 ## 示例 ### 获取所有节点的所有使用情况统计 ```bash GET /_cluster/nodes/usage ``` 或 ```bash GET /_nodes/usage ``` ### 获取指定节点的使用情况 ```bash GET /_nodes/node1/usage ``` ### 获取所有节点的 REST API 调用统计 ```bash GET /_nodes/usage/rest_actions ``` ### 获取本地节点的使用情况 ```bash GET /_nodes/_local/usage ``` **响应示例:** ```json { "cluster_name": "easysearch-cluster", "nodes": { "node1_id": { "name": "node-1", "host": "192.168.1.1", "ip": "192.168.1.1", "rest_actions": { "org.easysearch.rest.action.RestMainAction": 100, "org.easysearch.rest.action.RestSearchAction": 500, "org.easysearch.rest.action.RestIndexAction": 200 }, "aggregations": { "terms": 300, "date_histogram": 150, "avg": 200 }, "since": "2026-02-04T00:00:00Z" } } } ```