HeartBeat监控springboot服务状态

简介: HeartBeat监控springboot服务状态



一、环境准备

   部署模式:单节点部署。

   安装包:heartbeat安装包下载地址

二、安装部署

2.1 下载安装包到指定文件夹,并解压

# 进入安装目录
cd /opt/module
# 解压安装包
tar xf heartbeat-8.11.0.tar.gz

2.2 复制证书文件

# 进入配置文件目录
cd heartbeat-8.11.0/config
# 创建证书文件夹
mkdir certs
# 将es的证书文件复制到certs文件夹下
cp /opt/module/elasticsearch-8.11.0/config/certs/* certs/

2.3 编辑配置文件

vim heartbeat.yml
heartbeat.config.monitors:
  # Directory + glob pattern to search for configuration files
  path: ${path.config}/monitors.d/*.yml
  # If enabled, heartbeat will periodically check the config.monitors path for changes
  reload.enabled: false
  # How often to check for changes
  reload.period: 5s
# Configure monitors inline
heartbeat.monitors:
- type: http
  enabled: true
  id: logstash-226
  name: logstash-226
  urls: ["http://192.168.122.226:9600/_node"]
  schedule: '@every 30s'
  check.response.status: [200]
  ipv4: true
  ipv6: true
  mode: any
- type: tcp
  id: es-161
  name: es-161
  schedule: '@every 30s'
  hosts: ["192.168.10.161:9200"]
  ssl:
    certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"]
    certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt"
    key: "/opt/module/metricbeat-8.11.0/certs/instance.key"
- type: http
  # Set enabled to true (or delete the following line) to enable this monitor
  enabled: true
  # ID used to uniquely identify this monitor in Elasticsearch even if the config changes
  id: springboot-demo-test
  # Human readable display name for this service in Uptime UI and elsewhere
  name: springboot-demo-test
  # List of URLs to query
  urls: ["http://localhost:8080/test/hello"]
  # Configure task schedule
  schedule: '@every 10s'
  check.response.status: [200]
  ipv4: true
  ipv6: true
  mode: any
  # Total test connection and data exchange timeout
  #timeout: 16s
  # Name of corresponding APM service, if Elastic APM is in use for the monitored service.
  #service.name: my-apm-service-name
# Experimental: Set this to true to run heartbeat monitors exactly once at startup
#heartbeat.run_once: true
# ======================= Elasticsearch template setting =======================
setup.template.settings:
  index.number_of_shards: 1
  index.codec: best_compression
setup.template.name: "heartbeat"
setup.template.pattern: "heartbeat-*"
setup.ilm.enabled: false
# =================================== 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: "localhost:5601"
  host: "192.168.122.118:5601"
# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["https://192.168.122.118:9200","https://192.168.122.119:9200","https://192.168.122.120:9200"]
  protocol: "https"
  username: "elastic"
  password: "elastic"
  ssl.certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"]
  ssl.certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt"
  ssl.key: "/opt/module/metricbeat-8.11.0/certs/instance.key"
  # Protocol - either `http` (default) or `https`.
  #protocol: "https"
  # Authentication credentials - either API key or username/password.
  #api_key: "id:api_key"
  #username: "elastic"
  #password: "changeme"
# ================================= Processors =================================
processors:
  - add_observer_metadata:

2.4 设置模板

# 设置模板
./heartbeat setup

2.5 启动服务

# 编写启动命令文件
echo "nohup ./heartbeat -e  > ./heartbeat.log 2>&1 &" > start.sh
# 启动服务
./start.sh
# 查看日志
tail -200f /opt/module/heartbeat-8.11.0/heartbeat.log

2.6 检查es是否收到数据

登入kibana ,进入observability,添加 uptime,检查 heartbeat 状态。正常后即可在observability >uptime看到监控的实例

2.6 备用配置

     附上一段备用配置,适用各种场景的监控

heartbeat.monitors:
- type: http
  # Set enabled to true (or delete the following line) to enable this monitor
  enabled: true
  # ID used to uniquely identify this monitor in Elasticsearch even if the config changes
  id: ipu-cbs-server-test
  # Human readable display name for this service in Uptime UI and elsewhere
  name: ipu-cbs-server-test
  # List of URLs to query
  urls: ["http://192.168.122.251:10002/healthCheck/ready"]
  # Configure task schedule
  schedule: '@every 30s'
  check.response.status: [200]
  ipv4: true
  ipv6: true
  mode: any
- type: http
  enabled: true
  id: ipu-cbs-server-dev
  name: ipu-cbs-server-dev
  urls: ["http://192.168.122.239:10002/healthCheck/ready"]
  schedule: '@every 30s'
  check.response.status: [200]
  ipv4: true
  ipv6: true
  mode: any
- type: http
  enabled: true
  id: kibana-118
  name: kibana-118
  enabled: true
  schedule: '@every 30s' # 定期检查间隔
  urls: ["http://192.168.122.118:5601/login"]
  check.response.status: 200
  check.response.body: "kibana" # 检查响应体中是否包含指定的字符串
- type: http
  enabled: true
  id: kibana-119
  name: kibana-119
  enabled: true
  schedule: '@every 30s' # 定期检查间隔
  urls: ["http://192.168.122.119:5601/login"]
  check.response.status: 200
  check.response.body: "kibana" # 检查响应体中是否包含指定的字符串
- type: http
  enabled: true
  id: logstash-226
  name: logstash-226
  urls: ["http://192.168.122.226:9600/_node"]
  schedule: '@every 30s'
  check.response.status: [200]
  ipv4: true
  ipv6: true
  mode: any
- type: http
  enabled: true
  id: logstash-98
  name: logstash-98
  urls: ["http://192.168.122.98:9600/_node"]
  schedule: '@every 30s'
  check.response.status: [200]
  ipv4: true
  ipv6: true
  mode: any
- type: tcp
  id: es-161
  name: es-161
  schedule: '@every 30s'
  hosts: ["192.168.10.161:9200"]
  ssl:
    certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"]
    certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt"
    key: "/opt/module/metricbeat-8.11.0/certs/instance.key"
- type: tcp
  id: es-162
  name: es-162
  schedule: '@every 30s'
  hosts: ["192.168.10.162:9200"]
  ssl:
    certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"]
    certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt"
    key: "/opt/module/metricbeat-8.11.0/certs/instance.key"
- type: tcp
  id: es-163
  name: es-163
  schedule: '@every 30s'
  hosts: ["192.168.10.163:9200"]
  ssl:
    certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"]
    certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt"
    key: "/opt/module/metricbeat-8.11.0/certs/instance.key"
- type: tcp
  id: redis-28
  name: redis-28
  enabled: true
  schedule: '@every 10s'
  hosts: ["192.168.122.28:6379"]
  check.send: "AUTH Redis@123456\r\n"
- type: tcp
  schedule: '@every 10s'
  hosts: ["192.168.10.159:3306"]
  check.send: "SELECT 1;"
  enabled: true
  name: "mysql-159"
  id: "mysql-159"
  timeout: 10s
  max_retries: 10
  username: "tm_aseanbank_dev"
  password: "tm_aseanbank_dev"
  on_response_error:
    - action: log
      max_size: 10000
      keep_source: true
相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。  
相关文章
|
SQL 监控 druid
springboot-druid数据源的配置方式及配置后台监控-自定义和导入stater(推荐-简单方便使用)两种方式配置druid数据源
这篇文章介绍了如何在Spring Boot项目中配置和监控Druid数据源,包括自定义配置和使用Spring Boot Starter两种方法。
|
4月前
|
JavaScript Java 关系型数据库
基于springboot的美食城服务管理系统
本系统基于Spring Boot、Java、Vue和MySQL技术,构建集消费者服务、商家管理与后台监管于一体的美食城综合管理平台,提升运营效率与用户体验。
|
8月前
|
Prometheus 监控 Cloud Native
Spring Boot 可视化监控
本文介绍了如何通过Spring Actuator、Micrometer、Prometheus和Grafana为Spring Boot应用程序添加监控功能。首先创建了一个Spring Boot应用,并配置了Spring Actuator以暴露健康状态和指标接口。接着,利用Micrometer收集应用性能数据,并通过Prometheus抓取这些数据进行存储。最后,使用Grafana将Prometheus中的数据可视化,展示在精美的仪表板上。整个过程简单易行,为Spring Boot应用提供了基本的监控能力,同时也为后续扩展更详细的监控指标奠定了基础。
1453 2
|
7月前
|
Prometheus 监控 Cloud Native
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务
Docker 部署 Prometheus 和 Grafana 监控 Spring Boot 服务实现步骤
712 0
|
11月前
|
人工智能 自然语言处理 Java
对话即服务:Spring Boot整合MCP让你的CRUD系统秒变AI助手
本文介绍了如何通过Model Context Protocol (MCP) 协议将传统Spring Boot服务改造为支持AI交互的智能系统。MCP作为“万能适配器”,让AI以统一方式与多种服务和数据源交互,降低开发复杂度。文章以图书管理服务为例,详细说明了引入依赖、配置MCP服务器、改造服务方法(注解方式或函数Bean方式)及接口测试的全流程。最终实现用户通过自然语言查询数据库的功能,展示了MCP在简化AI集成、提升系统易用性方面的价值。未来,“对话即服务”有望成为主流开发范式。
8093 7
|
JavaScript Java 测试技术
基于SpringBoot+Vue实现的家政服务管理平台设计与实现(计算机毕设项目实战+源码+文档)
面向大学生毕业选题、开题、任务书、程序设计开发、论文辅导提供一站式服务。主要服务:程序设计开发、代码修改、成品部署、支持定制、论文辅导,助力毕设!
|
JavaScript NoSQL Java
基于SpringBoot+Vue实现的大学生就业服务平台设计与实现(系统源码+文档+数据库+部署等)
面向大学生毕业选题、开题、任务书、程序设计开发、论文辅导提供一站式服务。主要服务:程序设计开发、代码修改、成品部署、支持定制、论文辅导,助力毕设!
|
JSON Java 网络架构
elasticsearch学习四:使用springboot整合 rest 进行搭建elasticsearch服务
这篇文章介绍了如何使用Spring Boot整合REST方式来搭建和操作Elasticsearch服务。
437 4
elasticsearch学习四:使用springboot整合 rest 进行搭建elasticsearch服务
|
Prometheus 监控 Java
如何全面监控所有的 Spring Boot 微服务
如何全面监控所有的 Spring Boot 微服务
641 3