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可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
22天前
|
Java API 微服务
【Spring Boot系列】通过OpenAPI规范构建微服务服务接口
【4月更文挑战第5天】通过OpenAPI接口构建Spring Boot服务RestAPI接口
|
2月前
|
Web App开发 监控 Java
|
2月前
|
NoSQL Java Redis
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
小白版的springboot中集成mqtt服务(超级无敌详细),实现不了掐我头!!!
342 1
|
4月前
|
Dubbo Java 应用服务中间件
Spring Boot Dubbo 构建分布式服务
Spring Boot Dubbo 构建分布式服务
52 0
|
3月前
|
前端开发 Java 数据库连接
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
34 0
|
22天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的医院核酸检测服务系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的医院核酸检测服务系统的详细设计和实现
39 0
|
1月前
|
JSON 前端开发 安全
Springboot整合邮件服务
Springboot整合邮件服务
|
2月前
|
Prometheus 监控 Cloud Native
Spring Boot 应用可视化监控
Spring Boot 应用可视化监控
23 0
|
2月前
|
缓存 NoSQL Java
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
50 0
|
2月前
|
监控 druid Java
Spring Boot3整合Druid(监控功能)
Spring Boot3整合Druid(监控功能)
78 1