heartbeat 用来定时探测服务是否正常运行。支持ICMP、TCP 和 HTTP,也支持TLS、身份验证和代理。
1、下载并安装
root@web01:~# wget https://mirrors.tuna.tsinghua.edu.cn/elasticstack/7.x/apt/pool/main/h/heartbeat-elastic/heartbeat-7.17.8-amd64.deb
root@web01:~# dpkg -i heartbeat-7.17.8-amd64.deb
# 准备需要监控的服务httpd
root@web01:~# apt -y install apache2
2、修改配置
官方参考
# heartbeat.yml
heartbeat.monitors:
- type: icmp
id: ping-myhost
name: My Host Ping
hosts: ["myhost"]
schedule: '*/5 * * * * * *'
- type: tcp
id: myhost-tcp-echo
name: My Host TCP Echo
hosts: ["myhost:777"] # default TCP Echo Protocol
check.send: "Check"
check.receive: "Check"
schedule: '@every 5s'
- type: http
id: service-status
name: Service Status
service.name: my-apm-service-name
hosts: ["http://localhost:80/service/status"]
check.response.status: [200]
schedule: '@every 5s'
heartbeat.scheduler:
limit: 10
时间格式
Field name Mandatory? Allowed values Allowed special characters
---------- ---------- -------------- --------------------------
Seconds No 0-59 * / , -
Minutes Yes 0-59 * / , -
Hours Yes 0-23 * / , -
Day of month Yes 1-31 * / , - L W
Month Yes 1-12 or JAN-DEC * / , -
Day of week Yes 0-6 or SUN-SAT * / , - L #
Year No 1970–2099 * / , -
范例
root@web01:~# vim /etc/heartbeat/heartbeat.yml
heartbeat.monitors:
- type: http
# Set enabled to true (or delete the following line) to enable this example monitor
enabled: true
# 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.1.105:80"]
# Configure task schedule
schedule: '@every 10s'
- type: icmp
id: ping-myhost
name: My Host Ping
hosts: ["192.168.1.105"]
schedule: '*/5 * * * * * *'
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.1.104:5601"
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["192.168.1.101:9200"]
3、启动服务
root@web01:~# systemctl enable --now heartbeat-elastic.service
4、head 插件查看索引
![图片[1]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-40.png)
5、通过 Kibana 查看收集的性能指标
![图片[2]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-41.png)
![图片[3]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-42.png)
![图片[4]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-43.png)
![图片[5]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-44.png)
6、停止监控的服务再观察 Kibana
root@web01:~# systemctl stop apache2.service
![图片[6]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-45.png)
7、利用 Kibana 将 Heartbeat 的数据进行可视化
![图片[7]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-46.png)
![图片[8]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-47.png)
![图片[9]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-48.png)
![图片[10]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-49.png)
![图片[11]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-50.png)
![图片[12]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-51.png)
![图片[13]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-52.png)
![图片[14]-利用 Heartbeat 监控-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2023/01/image-53.png)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END