如何實現對ELK各組件的監控?試試Metricbeat


mark

一、前言

開發排查系統問題用得最多的手段就是查看系統日志,ELKElastic 公司開源的實時日志處理與分析解決方案,已經為日志處理方案的主流選擇。

而在生產環境中,如何針對 ELK 進行監控,保證各個組件正常運行?如何知道目前的資源是否能承受線上的壓力呢?本文主要是以 Elastic Stack 7.x 版本為例,介紹如何監控 ELK 自身的各個組件。

 

二、總體架構

常見的 Elastic Stack 日志系統架構如下

其中可使用 Metricbeat 組件作為輕量級監視代理,通過HTTP端點收集各個組件的監控信息,並把監控數據落盤到 Elasticsearch 中,最終通過 Kibana 以圖形化的方式展示各種監控數據。

 

三、部署Metricbeat

建議在每台服務器上都運行 Metricbeat 收集指標,多個Metricbeat實例的指標將在 Elasticsearch 服務器上合並。

下載對應版本的 Metricbeat 地址如下:

https://www.elastic.co/cn/downloads/past-releases#metricbeat

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 的控制台界面,進入 堆棧監測 菜單

 

即可查看各個組件的監控信息

 

掃碼關注有驚喜!

file


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM