Elastic 使用Heartbeat監測服務執行狀態

風來了,雨停了發表於2020-11-13

概述

Heartbeat是一個輕量級守護程式,通過在遠端伺服器上安裝,以定期檢查服務的狀態並確定它們是否可用。

在配置Heartbeat時,指定監視器來標識要檢查的主機名,每個監視器都根據指定的計劃執行。例如,你可以將一個監視器配置為每10分鐘執行一次,將另一個監視器配置為在9:00到17:00之間執行。

安裝配置 Heartbeat

下載安裝包:https://artifacts.elastic.co/downloads/beats/heartbeat/heartbeat-7.9.3-linux-x86_64.tar.gz

tar -zxvf heartbeat-7.9.3-linux-x86_64.tar.gz -C /usr/local/

進入Heartbeat的解壓目錄,修改 heartbeat.yml

vim heartbeat.yml

修改 output.elasticsearch:

# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["192.168.25.129:9200"]

修改 setup.kibana:

# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
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: "http://192.168.25.129:5601"

配置監視器 heartbeat.monitors:

heartbeat.monitors:
- type: http
  # ID used to uniquely identify this monitor in elasticsearch even if the config changes
  id: my-monitor
  # Human readable display name for this service in Uptime UI and elsewhere
  name: My Monitor
  # List or urls to query
  urls: ["http://192.168.25.129:9200"]
  # Configure task schedule
  schedule: '@every 5s'
  # Total test connection and data exchange timeout
  #timeout: 16s

啟動 Heartbeat

先執行預載入資源,Elasticsearch會建立對應的索引

./heartbeat setup -e

然後再啟動

./heartbeat

開啟Kibana,發現資料已經生成了,證明安裝成功

在這裡插入圖片描述

參考資料

官方文件:https://www.elastic.co/guide/en/beats/heartbeat/current/index.html

相關文章