文章七:ElasticSearch 集群监控指标

发布时间:2026/6/2 19:22:04

文章七:ElasticSearch 集群监控指标 ElasticSearch自带监控指标字段名称核心含义截图示例值NameElasticsearch 节点的唯一标识名称同时显示该节点的 Transport 通信地址与端口默认 9300 端口用于集群内节点间通信带★标记表示该节点是当前集群的主节点Master Nodenode-1192.168.0.190:9300Alerts该节点的告警状态用于标识节点是否触发了监控系统预设的告警规则Clear无告警状态正常Status该节点的运行状态标识节点是否正常接入集群、是否可正常提供服务Online节点在线正常运行Shards该节点当前承载的分片总数包含主分片Primary Shards和副本分片Replica Shards是衡量节点数据负载的核心指标之一18CPU Usage该节点的 CPU 使用率百分比反映节点的计算资源负载情况箭头↑表示数值较上一监控周期呈上升趋势1%上升趋势Load Average该节点的系统平均负载通常指 1 分钟内的 CPU 等待队列平均长度是衡量系统整体繁忙程度的核心指标箭头↑表示数值较上一监控周期呈上升趋势0.02上升趋势JVM Heap该节点 Elasticsearch 进程的 JVM 堆内存使用率百分比反映节点的内存资源占用情况箭头↑表示数值较上一监控周期呈上升趋势31%上升趋势Disk Free Space该节点数据存储目录的剩余可用磁盘空间箭头↓表示数值较上一监控周期呈下降趋势磁盘空间被数据占用9.9 GB下降趋势Elasticsearch 节点的参考阈值按 CPU 核心数以节点的 CPU 核心数为基准分档判断表格状态1 分钟 Load Average 阈值说明✅ 健康≤ CPU 核心数的 0.7 倍系统负载低资源充足无性能压力⚠️ 预警CPU 核心数的 0.7 ~ 1 倍负载开始升高CPU 接近饱和需关注趋势❌ 异常≥ CPU 核心数的 1 ~ 2 倍CPU 已经被完全打满任务排队可能出现查询超时、写入延迟 严重≥ CPU 核心数的 2 倍以上系统负载极高可能导致节点假死、集群不稳定举个例子你的节点如果是4 核 CPU正常Load ≤ 2.8预警2.8 ~ 4异常≥ 4你的截图里Load Average 0.02无论节点是几核哪怕是 1 核都属于极低负载完全正常。节点管理集群横向扩容实战禁用集群自动平衡因为我们添加新的节点时他会自动的将分片进行平衡但是如果我们的节点启动失败就会造成问题。还有就是假设我们增加多个节点的话每个节点的加入都会让他进行一次资源的平衡这个也占用es的资源。PUT _cluster/settings { persistent: { cluster: { routing: { rebalance.enable:none } } } }参数含义让 Elasticsearch 自动把分片均匀分配到所有节点上不让某个节点压力太大。一键获取完整项目代码新增节点全部部署之后重新开启节点下线将需要下线的节点执行下面的命令之后这个节点上的分片就会被分配到其他的节点上。PUT _cluster/settings { persistent: { cluster.routing.allocation.exclude._ip: 要下线的节点IP } } PUT _cluster/settings { persistent: { cluster.routing.allocation.exclude._host: 主机名 } } PUT _cluster/settings { persistent: { cluster.routing.allocation.exclude._name: 节点名称 } }集群监控集群健康状态状态含义核心风险green所有主分片 副本分片 都正常分配完成✅ 完全健康无任何问题yellow所有主分片正常分配但部分副本分片未分配⚠️ 数据冗余度不足单节点故障可能导致数据丢失red至少有一个主分片及其副本未分配部分索引不可用❌ 集群功能受损数据读写失败业务受影响Elasticsearch 集群自我监控Monitoring在 Elasticsearch 中集群内置的 X-Pack 自我监控模块会自动采集节点、索引、集群性能等核心监控指标我们可以动态开启 / 关闭监控数据采集也能自定义监控采集间隔实现精细化管控。所有配置均支持在线动态生效无需重启集群操作便捷且不影响业务运行。一、集群自我监控开关控制监控采集功能支持两种持久化配置persistent永久生效集群重启后保留、transient临时生效集群重启后失效推荐使用永久配置。1. 开启集群自我监控启动数据采集执行以下请求启用监控数据采集功能集群会开始自动收集各项运行指标json// 永久开启自我监控持续采集集群、节点、索引监控数据 PUT _cluster/settings { persistent: { xpack.monitoring.collection.enabled: true }, transient: {} }2. 关闭集群自我监控停止数据采集若无需监控可执行以下命令动态关闭停止所有监控数据的生成json// 永久关闭自我监控停止采集监控数据 PUT _cluster/settings { persistent: { xpack.monitoring.collection.enabled: false }, transient: {} }二、修改监控数据采集间隔Elasticsearch默认监控采集间隔为 10 秒我们可以根据业务需求调整间隔缩短间隔获取更精细、实时的监控数据适用于性能调试、高并发场景延长间隔降低集群资源消耗适用于日常稳定运行场景。配置采集间隔动态修改执行以下命令自定义采集周期单位为毫秒ms示例修改为5 秒5000msjson// 永久修改监控采集间隔为 5 秒精细化采集 PUT _cluster/settings { persistent: { xpack.monitoring.collection.interval: 1000ms } }常用配置参考精细监控1000ms1 秒默认配置10000ms10 秒节能模式30000ms30 秒修改之后他的增速变快基于 Metricbeat 的分离式监控采集这里为大家提供一下铭毅天下的安装课程如何借助 Metricbeat kibana 实现 Elasticsearch 8.X 集群的可视化监控_哔哩哔哩_bilibili在 Elasticsearch 生产集群中传统的内置自监控xpack.monitoring存在与业务抢占资源、监控数据与业务数据混存、配置项废弃等问题尤其在高并发持续写入场景下会加剧磁盘压力并影响集群稳定性Elastic。为此Elastic 官方在 7.16 版本后强烈推荐采用Metricbeat 分离采集架构将监控能力从集群内部剥离实现监控与生产解耦。Metricbeat 是 Elastic Stack 中的轻量指标采集器可独立部署于生产集群之外或各节点上主动拉取 Elasticsearch 的节点状态、索引分片、JVM、磁盘、段合并、线程池等核心指标并统一上报至独立的监控集群进行存储与展示Elastic。这种架构的核心优势在于生产集群仅暴露查询接口不承担监控数据的生成与存储压力有效避免监控操作影响写入性能同时监控数据独立存储即使生产集群磁盘爆满或宕机仍可完整保留监控日志用于故障回溯。在配置层面需在 Metricbeat 中启用elasticsearch-xpack模块并开启 xpack 模式替代原有废弃的xpack.monitoring.collection.enabled与interval参数Elastic。采集周期可在 Metricbeat 中统一配置默认 10s不再依赖集群级别设置Elastic。通过将输出指向独立监控集群实现监控数据流与业务数据流完全隔离从根本上解决自监控带来的磁盘占用与性能干扰问题特别适合大规模、高写入压力的 Elasticsearch 生产环境Elastic。集群配置matricbeat步骤指定监控集群地址下载解压metrixbeat文件官方下载和安装文件Metricbeat quick start: installation and configuration | Metricbeat Reference [8.5] | Elastic官方软件下载地址Metricbeat 8.5.2 | Elastic 具体的版本大家可以自行设置drwxr-xr-x. 12 elastic elastic 268 5月 31 18:20 elasticsearch-8.5.2 -rwxr-xr-x. 1 elastic elastic 580694330 3月 1 15:02 elasticsearch-8.5.2-linux-x86_64.tar.gz drwxrwxr-x. 11 elastic elastic 222 5月 31 18:39 kibana-8.5.2 -rw-r--r--. 1 elastic elastic 223272744 5月 20 23:59 kibana-8.5.2-linux-x86_64.tar.gz -rw-r--r--. 1 root root 48141481 6月 1 11:16 metricbeat-8.5.2-linux-x86_64.tar.gz启用 Elasticsearch x-pack 模块在文件解压缩之后执行命令启用 Elasticsearch x-pack 模块./metricbeat modules enable elasticsearch-xpack执行之后显示[elasticlocalhost metricbeat-8.5.2-linux-x86_64]$ ./metricbeat modules enable elasticsearch-xpack Enabled elasticsearch-xpack配置modules.d/elasticsearch-xpack.yml.文件如果是8.1版本的在配置这个配置文件之前在es的集群配置中需要先打开配置PUT _cluster/settings{persistent: {xpack.monitoring.collection.enabled: true}}但是其他的可能不需要具体是否需要还是看对应版本的官网Collecting Elasticsearch monitoring data with Metricbeat | Elasticsearch Guide [8.1] | Elastic# 启用 Elasticsearch 模块Metricbeat 内置模块 - module: elasticsearch # 开启 X-Pack 监控模式核心 # 作用自动采集 ES 的集群/节点/索引等监控指标 # 并按 Kibana Monitoring 要求的格式输出不用自己配 metricsets。 xpack.enabled: true # 采集周期每 10 秒拉一次 ES 监控数据 period: 10s # 要监控的 ES 地址这里填被监控的生产 ES # 格式[http://IP:9200]多个节点用逗号分隔 hosts: [http://localhost:9200] # 可选采集范围node只采集当前节点cluster整集群 #scope: node # 可选ES 开启安全认证时用的账号 #username: user # 可选ES 密码 #password: secret # 可选是否开启 SSLES 用 HTTPS 时必须打开 #ssl.enabled: true # 可选CA 证书路径用来验证 ES 服务器证书合法性 #ssl.certificate_authorities: [/etc/pki/root/ca.pem] # 可选Metricbeat 客户端证书双向认证时用 #ssl.certificate: /etc/pki/client/cert.pem # 可选Metricbeat 客户端私钥 #ssl.key: /etc/pki/client/cert.key # 可选SSL 证书校验策略 # full严格校验生产推荐none不校验测试用 #ssl.verification_mode: full安全模式下标准配置文件# Module: elasticsearch # Docs: https://www.elastic.co/guide/en/beats/metricbeat/8.5/metricbeat-module-elasticsearch.html - module: elasticsearch xpack.enabled: true period: 10s hosts: [https://192.168.0.190:9200] username: elastic password: 2ok8JzOq_kF-or*hcOpK ssl.enabled: true ssl.certificate_authorities: [/elasticsearch/elasticsearch-8.5.2/config/certs/http_ca.crt]配置 Metricbeat让它把数据发送到监控集群下面的配置修改方式都是直接借鉴的官网大家可以看一下官网解释的原因和配置的方法Set the host and port where Metricbeat can find the Elasticsearch installation, and set the username and password of a user who is authorized to set up Metricbeat. For example:output.elasticsearch: hosts: [https://myEShost:9200] username: metricbeat_internal password: YOUR_PASSWORD ssl: enabled: true ca_trusted_fingerprint: b9a10bbe64ee9826abeda6546fc988c8bf798b41957c33d05db736716513dc9cThis example shows a hard-coded password, but you should store sensitive values in the secrets keystore.This example shows a hard-coded fingerprint, but you should store sensitive values in the secrets keystore. The fingerprint is a HEX encoded SHA-256 of a CA certificate, when you start Elasticsearch for the first time, security features such as network encryption (TLS) for Elasticsearch are enabled by default. If you are using the self-signed certificate generated by Elasticsearch when it is started for the first time, you will need to add its fingerprint here. The fingerprint is printed on Elasticsearch start up logs, or you can refer to connect clients to Elasticsearch documentation for other options on retrieving it. If you are providing your own SSL certificate to Elasticsearch refer to Metricbeat documentation on how to setup SSL.If you plan to use our pre-built Kibana dashboards, configure the Kibana endpoint. Skip this step if Kibana is running on the same host as Elasticsearch.setup.kibana: host: mykibanahost:5601 username: my_kibana_user password: {pwd}The hostname and port of the machine where Kibana is running, for example,mykibanahost:5601. If you specify a path after the port number, include the scheme and port:http://mykibanahost:5601/path.Theusernameandpasswordsettings for Kibana are optional. If you don’t specify credentials for Kibana, Metricbeat uses theusernameandpasswordspecified for the Elasticsearch output.To use the pre-built Kibana dashboards, this user must be authorized to view dashboards or have thekibana_adminbuilt-in role.当前配置文件有问题 #这里配置的是将监控数据上报的监控节点 output.elasticsearch: # Array of hosts to connect to. hosts: [192.168.0.190:9200] # Protocol - either http (default) or https. protocol: https # Authentication credentials - either API key or username/password. #api_key: id:api_key username: elastic password: 2ok8JzOq_kF-or*hcOpK 上面的配置再开启安全的情况下再数据的采集端是正常的但是再数据的写入时出现证书不信任的问题所以需要再下面加上ssl的基本配置 官网地址https://www.elastic.co/guide/en/beats/metricbeat/8.5/elasticsearch-output.html output.elasticsearch: # Array of hosts to connect to. hosts: [192.168.0.190:9200] # Protocol - either http (default) or https. protocol: https # Authentication credentials - either API key or username/password. #api_key: id:api_key username: elastic password: 2ok8JzOq_kF-or*hcOpK ssl.enabled: true ssl.certificate_authorities: [/elasticsearch/elasticsearch-8.5.2/config/certs/http_ca.crt] setup.kibana: # Kibana Host # Scheme and port can be left out and will be set to the default (http and 5601) # In case you specify and additional path, the scheme is required: http://localhost:5601/path # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601 host: 192.168.0.190:5601之后使用root的权限启动就可以了生产建议上面再配置中使用的是超级用户的权限但是再官网中有这么一段话If Elastic security features are enabled, you must also provide a user ID and password so that Metricbeat can collect metrics successfully:Create a user on the production cluster that has the remote_monitoring_collector built-in role. Alternatively, use the remote_monitoring_user built-in user.Add theusernameandpasswordsettings to the Elasticsearch module configuration file.If TLS is enabled on the HTTP layer of your Elasticsearch cluster, you must either use https as the URL scheme in thehostssetting or add thessl.enabled: truesetting. Depending on the TLS configuration of your Elasticsearch cluster, you might also need to specify additional ssl.* settings.你当前使用的是elastic超级管理员用户拥有集群最高权限测试环境可用、生产环境不推荐官方明确要求监控采集必须使用专用低权限用户禁止使用超级管理员官方提供两种合规方案使用内置用户remote_monitoring_user自带采集权限自定义用户 内置角色remote_monitoring_collector若集群开启TLS/HTTPS必须配置证书、协议保证加密通信正常Metricbeat 的setup.kibana会自动继承output.elasticsearch的账号密码用于自动加载监控仪表盘无需单独配置。配置文件标准模板1模块采集配置modules.d/elasticsearch-xpack.yml- module: elasticsearch xpack.enabled: true period: 10s # 连接本机ES生产必须用https hosts: [https://localhost:9200] # 官方推荐生产专用监控采集用户 username: remote_monitoring_user password: 你的用户密码 # 开启TLS ssl.enabled: true ssl.certificate_authorities: [/elasticsearch/config/http_ca.crt]2数据输出配置metricbeat.ymloutput.elasticsearch: hosts: [https://监控集群IP:9200] # 写入监控集群同样使用专用用户 username: remote_monitoring_user password: 你的密码 ssl.enabled: true ssl.certificate_authorities: [/path/to/ca.crt] setup.kibana: host: http://kibanaIP:5601 # 自动继承output中的账号密码加载仪表盘无需重复配置

相关新闻