关于java:如何实现对ELK各组件的监控试试Metricbeat

10次阅读

共计 2674 个字符,预计需要花费 7 分钟才能阅读完成。

一、前言

开发排查零碎问题用得最多的伎俩就是查看系统日志,ELKElastic 公司开源的实时日志解决与剖析解决方案,曾经为日志解决计划的支流抉择。

而在生产环境中,如何针对 ELK 进行监控,保障各个组件失常运行?如何晓得目前的资源是否能接受线上的压力呢?本文次要是以 Elastic Stack 7.x 版本为例,介绍如何监控 ELK 本身的各个组件。

 

二、总体架构

常见的 Elastic Stack 日志零碎架构如下

其中可应用 Metricbeat 组件作为轻量级监督代理,通过 HTTP 端点收集各个组件的监控信息,并把监控数据落盘到 Elasticsearch 中,最终通过 Kibana 以图形化的形式展现各种监控数据。

 

三、部署 Metricbeat

倡议在每台服务器上都运行 Metricbeat 收集指标,多个 Metricbeat 实例的指标将在 Elasticsearch 服务器上合并。

下载对应版本的 Metricbeat 地址如下:

https://www.elastic.co/cn/dow…

3.1. 收集 Elasticsearch 信息

Metricbeat 中启用并配置 Elasticsearch x-pack 模块
从装置目录中,运行:

./metricbeat modules enable elasticsearch-xpack

默认状况下,模块从 http://localhost:9200 收集 Elasticsearch 指标。如果本地服务器有不同的地址,请在 modules.d/elasticsearch-xpack.yml 中将其增加到主机设置。

 

3.2. 收集 Kibana 信息

Metricbeat 中启用并配置 Kibana x-pack 模块

./metricbeat modules enable kibana-xpack

该模块将默认从 http://localhost:5601 收集 Kibana 监测指标。如果本地 Kibana 实例有不同的地址,则必须通过 modules.d/kibana-xpack.yml 文件中的 hosts 设置进行指定。

 

3.3. 收集 Logstash 信息

Metricbeat 中启用并配置 Logstash x-pack 模块

./metricbeat modules enable logstash-xpack

该模块将默认从 http://localhost:9600 收集 Logstash 监测指标。如果本地 Logstash 实例有不同的地址,则必须通过 modules.d/logstash-xpack.yml 文件中的 hosts 设置进行指定。

 

3.4. 收集 Beats 信息

所有类型的 Beats 配置都一样

3.4.1. 开启 HTTP 端点

须要开启 Beats 本人的 HTTP 端点输入监控数据,例如 Filebeat 批改 filebeat.yml 文件,在最初增加以下配置

http:
  enabled: true
  host: 0.0.0.0
  port: 5066

3.4.2. 启用 Beat 模块

Metricbeat 中启用并配置 Beat x-pack 模块

./metricbeat modules enable beat-xpack

该模块将默认从 http://localhost:5066 收集 beat 监测指标。如果正在监测的 beat 实例有不同的地址,则必须通过 modules.d/beat-xpack.yml 文件中的 hosts 设置进行指定。

 

3.5. 数据输入配置

配置 Metricbeat 以发送至监测集群,在 metricbeat.yml 文件中批改以下内容

output.elasticsearch:
  hosts: ["http://localhost:9200"] ## Monitoring cluster

  # Optional protocol and basic auth credentials.
  #protocol: "https"
  #username: "elastic"
  #password: "changeme"

PS:地址、用户名和明码按理论状况批改

 

3.6. 启动 Metricbeat

./metricbeat -e

 

四、收集 Elasticsearch 日志

应用 Filebeat 收集 Elasticsearch 本身的日志数据。

首先须要在 Elasticsearch 所在的服务器中装置 Filebeat 组件。

4.1. 启用 es 模块

Filebeat 中启用并配置 Elasticsearch 模块,执行以下命令

./filebeat modules enable elasticsearch

 

4.2. 配置 es 模块

批改 es 模块的配置信息,指定日志门路

vim modules.d/elasticsearch.yml

批改为以下内容

- module: elasticsearch
  server:
    enabled: true
    var.paths:
      - /app/elk/elasticsearch/logs/*_server.json

  gc:
    enabled: true
    var.paths:
      - /app/elk/elasticsearch/logs/gc.log.[0-9]*
      - /app/elk/elasticsearch/logs/gc.log

  audit:
    enabled: true
    var.paths:
      - /app/elk/elasticsearch/logs/*_audit.json

  slowlog:
    enabled: true
    var.paths:
      - /app/elk/elasticsearch/logs/*_index_search_slowlog.json
      - /app/elk/elasticsearch/logs/*_index_indexing_slowlog.json

  deprecation:
    enabled: true
    var.paths:
      - /app/elk/elasticsearch/logs/*_deprecation.json

PS:日志门路按理论状况批改

 

4.3. 配置输入

批改 filebeat.yml 文件,配置 es 相干信息

output.elasticsearch:
  hosts: ["localhost:9200"]
  
  # Optional protocol and basic auth credentials.
  #protocol: "https"
  #username: "elastic"
  #password: "changeme"

PS:地址、用户名和明码按理论状况批改

 

4.4. 启动 Filebeat

./filebeat -c filebeat.yml -e

 

五、查看监控界面

进入 Kibana 的控制台界面,进入 堆栈监测 菜单

 

即可查看各个组件的监控信息

 

扫码关注有惊喜!

正文完
 0