HeartBeat监控springboot服务状态

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: 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
相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
3月前
|
SQL 监控 druid
springboot-druid数据源的配置方式及配置后台监控-自定义和导入stater(推荐-简单方便使用)两种方式配置druid数据源
这篇文章介绍了如何在Spring Boot项目中配置和监控Druid数据源,包括自定义配置和使用Spring Boot Starter两种方法。
|
5月前
|
Java Spring
Spring boot 运行服务jar外配置配置文件方式总结
Spring boot 运行服务jar外配置配置文件方式总结
961 0
|
2月前
|
JSON Java 网络架构
elasticsearch学习四:使用springboot整合 rest 进行搭建elasticsearch服务
这篇文章介绍了如何使用Spring Boot整合REST方式来搭建和操作Elasticsearch服务。
130 4
elasticsearch学习四:使用springboot整合 rest 进行搭建elasticsearch服务
|
3月前
|
缓存 前端开发 Java
springboot 的单体服务 字典参数转译
本文介绍了如何在Spring Boot项目中使用缓存来管理字典参数,并确保前后端数据一致性。首先,通过`@EnableCaching`启用缓存功能,接着创建一个自定义的字典缓存类`DicCache`。然后,通过配置类将`DicCache`添加到`cacheManager`中。此外,对字典服务进行改造,使用`@CachePut`和`@CacheEvict`注解保证数据一致性。最后,实现自定义注解`@DicSerializer`和序列化处理类`DictSerializerHandel`,用于在序列化过程中自动转换字典值。通过这种方式,可最小化代码改动并提高系统性能。
springboot 的单体服务 字典参数转译
|
2月前
|
监控 Dubbo Java
dubbo学习三:springboot整合dubbo+zookeeper,并使用dubbo管理界面监控服务是否注册到zookeeper上。
这篇文章详细介绍了如何将Spring Boot与Dubbo和Zookeeper整合,并通过Dubbo管理界面监控服务注册情况。
101 0
dubbo学习三:springboot整合dubbo+zookeeper,并使用dubbo管理界面监控服务是否注册到zookeeper上。
|
2月前
|
自然语言处理 Java Maven
elasticsearch学习二:使用springboot整合TransportClient 进行搭建elasticsearch服务
这篇博客介绍了如何使用Spring Boot整合TransportClient搭建Elasticsearch服务,包括项目创建、Maven依赖、业务代码和测试示例。
109 0
elasticsearch学习二:使用springboot整合TransportClient 进行搭建elasticsearch服务
消息中间件 缓存 监控
129 0
|
4月前
|
小程序 JavaScript Java
微信小程序+SpringBoot接入后台服务,接口数据来自后端
这篇文章介绍了如何将微信小程序与SpringBoot后端服务进行数据交互,包括后端接口的编写、小程序获取接口数据的方法,以及数据在小程序中的展示。同时,还涉及到了使用Vue搭建后台管理系统,方便数据的查看和管理。
微信小程序+SpringBoot接入后台服务,接口数据来自后端
|
4月前
|
Java Windows
SpringBoot Windows 自启动 - 通过 Windows Service 服务实现
SpringBoot Windows 自启动 - 通过 Windows Service 服务实现
133 2
|
4月前
|
Java 开发者 Spring
"揭秘SpringBoot魔法SPI机制:一键解锁服务扩展新姿势,让你的应用灵活飞天!"
【8月更文挑战第11天】SPI(Service Provider Interface)是Java的服务提供发现机制,用于运行时动态查找和加载服务实现。SpringBoot在其基础上进行了封装和优化,通过`spring.factories`文件提供更集中的配置方式,便于框架扩展和组件替换。本文通过定义接口`HelloService`及其实现类`HelloServiceImpl`,并在`spring.factories`中配置,结合`SpringFactoriesLoader`加载服务,展示了SpringBoot SPI机制的工作流程和优势。
61 5