--- title: "获取节点统计信息" date: 2026-03-04 lastmod: 2026-03-04 description: "获取集群中节点的统计信息,包括操作系统、JVM、索引、网络等性能指标" tags: ["集群管理", "节点统计", "监控", "性能分析"] summary: "获取集群中节点的统计信息,包括操作系统、JVM、索引、网络等方面的性能指标和资源使用情况。 API # GET /_cluster/nodes/stats GET /_nodes/stats GET /_nodes/{nodeId}/stats GET /_nodes/stats/{metric} GET /_nodes/{nodeId}/stats/{metric} GET /_nodes/stats/{metric}/{index_metric} GET /_nodes/{nodeId}/stats/{metric}/{index_metric} API 的作用 # 该 API 用于获取集群中节点的统计信息,可以返回关于集群中各个节点的各种性能指标、资源使用情况和系统状态,包括操作系统、JVM、索引、网络等方面的统计数据。 可用的统计指标(metric) # 指标值 描述 _all 所有指标 breaker 断路器统计 fs 文件系统统计 http HTTP 统计 indices 索引统计 jvm JVM 统计 os 操作系统统计 process 进程统计 thread_pool 线程池统计 transport 传输统计 discovery 发现统计 indexing_pressure 索引压力统计 索引级别的指标(index_metric) # 当 metric 为 indices 时,可以进一步指定以下指标:" --- 获取集群中节点的统计信息,包括操作系统、JVM、索引、网络等方面的性能指标和资源使用情况。 ## API ``` GET /_cluster/nodes/stats GET /_nodes/stats GET /_nodes/{nodeId}/stats GET /_nodes/stats/{metric} GET /_nodes/{nodeId}/stats/{metric} GET /_nodes/stats/{metric}/{index_metric} GET /_nodes/{nodeId}/stats/{metric}/{index_metric} ``` ## API 的作用 该 API 用于获取集群中节点的统计信息,可以返回关于集群中各个节点的各种性能指标、资源使用情况和系统状态,包括操作系统、JVM、索引、网络等方面的统计数据。 ### 可用的统计指标(metric) | 指标值 | 描述 | |--------|------| | `_all` | 所有指标 | | `breaker` | 断路器统计 | | `fs` | 文件系统统计 | | `http` | HTTP 统计 | | `indices` | 索引统计 | | `jvm` | JVM 统计 | | `os` | 操作系统统计 | | `process` | 进程统计 | | `thread_pool` | 线程池统计 | | `transport` | 传输统计 | | `discovery` | 发现统计 | | `indexing_pressure` | 索引压力统计 | ### 索引级别的指标(index_metric) 当 `metric` 为 `indices` 时,可以进一步指定以下指标: | 指标值 | 描述 | |--------|------| | `_all` | 所有索引指标 | | `completion` | 完成度统计 | | `docs` | 文档统计 | | `fielddata` | 字段数据统计 | | `query_cache` | 查询缓存统计 | | `flush` | 刷新统计 | | `get` | 获取操作统计 | | `indexing` | 索引操作统计 | | `merge` | 合并统计 | | `request_cache` | 请求缓存统计 | | `refresh` | 刷新统计 | | `search` | 搜索统计 | | `segments` | 段统计 | | `store` | 存储统计 | | `warmer` | 预热统计 | | `suggest` | 建议统计 | ## API 的参数 ### 路由参数 | 参数 | 类型 | 是否必填 | 默认值 | 描述 | |------|------|----------|--------|------| | `{nodeId}` | 字符串 | 否 | 所有节点 | 节点 ID 或名称列表(逗号分隔)。特殊值:`_local` 表示当前连接的节点 | | `{metric}` | 字符串 | 否 | `_all` | 指标类型名称 | | `{index_metric}` | 字符串 | 否 | - | 索引级别的具体指标(仅当 `metric` 为 `indices` 时有效) | ### Query String 参数 | 参数 | 类型 | 是否必填 | 默认值 | 描述 | |------|------|----------|--------|------| | `nodeId` | 字符串 | 否 | 所有节点 | 指定要获取统计信息的节点(逗号分隔)。特殊值:`_local` 表示当前连接的节点 | | `metric` | 字符串 | 否 | `_all` | 指定要获取的指标类型(逗号分隔) | | `index_metric` | 字符串 | 否 | `_all` | 指定索引级别的具体指标(逗号分隔)。仅当 `metric` 包含 `indices` 时有效 | | `level` | 枚举值 | 否 | `node` | 指定索引统计的聚合级别。可选值:`indices`(按索引聚合)、`node`(按节点聚合)、`shards`(按分片聚合) | | `timeout` | 时间值 | 否 | 默认超时 | 操作超时时间 | | `include_segment_file_sizes` | 布尔值 | 否 | `false` | 是否报告每个 Lucene 索引文件的聚合磁盘使用量(仅当请求段统计时适用) | | `fields` | 字符串 | 否 | - | 指定 fielddata 和 completion 索引指标的字段(支持通配符,逗号分隔) | | `fielddata_fields` | 字符串 | 否 | - | 指定 fielddata 索引指标的字段(支持通配符,逗号分隔) | | `completion_fields` | 字符串 | 否 | - | 指定 completion 索引指标的字段(支持通配符,逗号分隔) | | `groups` | 字符串 | 否 | - | 指定搜索索引指标的搜索组(逗号分隔) | | `types` | 字符串 | 否 | - | 指定索引索引指标的文档类型(逗号分隔) | ## 示例 ### 获取所有节点的所有统计信息 ```bash GET /_cluster/nodes/stats ``` 或 ```bash GET /_nodes/stats ``` ### 获取指定节点的统计信息 ```bash GET /_nodes/node1/stats ``` ### 获取所有节点的 JVM 统计 ```bash GET /_nodes/stats/jvm ``` ### 获取指定节点的索引统计 ```bash GET /_nodes/node1/stats/indices ``` ### 获取索引的文档统计 ```bash GET /_nodes/stats/indices/docs ``` ### 获取索引的搜索统计(按分片级别) ```bash GET /_nodes/stats/indices/search?level=shards ``` ### 获取本地节点的信息 ```bash GET /_nodes/_local/stats ``` ### 获取多个节点的多个指标 ```bash GET /_nodes/node1,node2/stats/jvm,os,process ``` **响应示例:** ```json { "cluster_name": "easysearch-cluster", "nodes": { "node1_id": { "name": "node-1", "host": "192.168.1.1", "ip": "192.168.1.1", "jvm": { "mem": { "heap_used_in_bytes": 536870912, "heap_max_in_bytes": 1073741824, "heap_used_percent": 50 }, "gc": { "collectors": { "young": { "collection_count": 100, "collection_time_in_millis": 500 } } } }, "os": { "cpu_percent": 25, "load_average": [1.5, 1.2, 1.0] }, "indices": { "docs": { "count": 10000, "deleted": 100 }, "store": { "size_in_bytes": 1073741824 }, "search": { "open_contexts": 5, "query_total": 1000, "query_time_in_millis": 5000 } } } } } ```