当前位置: 首页 > wzjs >正文

企业网站首页的实现淮安新港建设有限公司网站

企业网站首页的实现,淮安新港建设有限公司网站,建工网一级建造师论坛,论述网站建设的主要内容目录 前言1. Demo2. 拓展 前言 🤟 找工作,来万码优才:👉 #小程序://万码优才/r6rqmzDaXpYkJZF Spring Boot 的 actuator 提供了应用监控的功能,其中健康检查(Health Check)是一个重要的部分&…

目录

  • 前言
  • 1. Demo
  • 2. 拓展

前言

🤟 找工作,来万码优才:👉 #小程序://万码优才/r6rqmzDaXpYkJZF

Spring Boot 的 actuator 提供了应用监控的功能,其中健康检查(Health Check)是一个重要的部分,可以自定义健康检查,并且可以单独设置 Actuator 端口

1. Demo

实战中的Demo可用于如下:

  • 检测某个外部服务是否可用
  • 监测某个业务逻辑的状态

如果是 Maven 项目,需在 pom.xml 中添加:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

启用 Actuator 端点

在 application.yml 配置文件中:

management:endpoints:web:exposure:include: health # 只暴露健康检查端点health:show-details: always # 显示详细健康信息

或者是在application/properties:

management.endpoints.web.base-path=/actuator
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

自定义健康检查,自定义 HealthIndicator 需要实现 org.springframework.boot.actuate.health.HealthIndicator 接口,覆盖 health() 方法:

  • Health.up():表示服务状态正常
  • Health.down():表示服务状态异常
  • withDetail():添加额外的诊断信息
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;@Component
public class CustomHealthIndicator implements HealthIndicator {@Overridepublic Health health() {// 模拟检查逻辑(比如检查某个服务是否可用)boolean serviceRunning = checkServiceStatus();if (serviceRunning) {return Health.up().withDetail("service", "Running").build();} else {return Health.down().withDetail("service", "Down").withDetail("reason", "Service Unreachable").build();}}private boolean checkServiceStatus() {// 模拟服务状态检查return Math.random() > 0.5;}
}

后续增加一个启动类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** @description: 自动装配知识点* @Author lxs* @Date 2025/3/17 14:26*/
@SpringBootApplication
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}

总体截图如下:

在这里插入图片描述

访问如下:http://127.0.0.1:8080/actuator/health,0.5的概率随机

在这里插入图片描述

基本的知识如下:
status: UP 表示应用状态正常
customHealthIndicator 是我们自定义的健康检查
diskSpace 表示磁盘健康情况

也可配置不一样的端口号
在 application.yml 中:

server:port: 8080  # 主应用端口management:server:port: 9000  # Actuator 端口endpoints:web:exposure:include: "*"  # 暴露所有 Actuator 端点
  1. 访问 Actuator 端点
    应用运行后:
    http://localhost:8080/ 访问主应用
    http://localhost:9000/actuator/health 访问健康检查

2. 拓展

常见的 Actuator 端点

端点说明访问地址
/actuator查看所有可用端点http://localhost:9000/actuator
/actuator/health查看应用健康状态http://localhost:9000/actuator/health
/actuator/info查看应用信息http://localhost:9000/actuator/info
/actuator/metrics查看应用指标http://localhost:9000/actuator/metrics
/actuator/metrics/{name}查看具体指标(如 jvm.memory.used)http://localhost:9000/actuator/metrics/jvm.memory.used
/actuator/mappings查看所有 Spring MVC 映射http://localhost:9000/actuator/mappings
/actuator/loggers查看和修改日志级别http://localhost:9000/actuator/loggers
/actuator/env查看环境变量http://localhost:9000/actuator/env
/actuator/beans查看 Spring Bean 信息http://localhost:9000/actuator/beans
/actuator/threaddump线程 Dump 信息http://localhost:9000/actuator/threaddump
/actuator/shutdown关闭应用(默认禁用)http://localhost:9000/actuator/shutdown
  1. 只暴露部分端点
management:endpoints:web:exposure:include: "health,info,metrics"

访问 http://localhost:9000/actuator:

{"_links": {"self": { "href": "http://localhost:9000/actuator", "templated": false },"health": { "href": "http://localhost:9000/actuator/health", "templated": false },"info": { "href": "http://localhost:9000/actuator/info", "templated": false },"metrics": { "href": "http://localhost:9000/actuator/metrics", "templated": false }}
}
  1. 关闭特定端点
management:endpoint:shutdown:enabled: false  # 禁用 shutdown 端点,防止误操作health:enabled: true  # 启用健康检查

访问 http://localhost:9000/actuator/shutdown:

{"error": "Not Found","status": 404
}
  1. 配置 metrics 指标
    jvm.memory.used 监测 JVM 内存占用
    system.cpu.usage 监测 CPU 使用率
management:metrics:export:prometheus:enabled: true  # 启用 Prometheus 监控

访问 http://localhost:9000/actuator/metrics

{"names": ["jvm.memory.used","jvm.memory.max","http.server.requests","system.cpu.usage"]
}

访问 http://localhost:9000/actuator/metrics/jvm.memory.used

{"name": "jvm.memory.used","measurements": [{"statistic": "VALUE","value": 25000000}],"availableTags": [{"tag": "area","values": ["heap", "nonheap"]}]
}

可以暴露 Prometheus 监控数据,方便与 Grafana 配合使用


文章转载自:

http://nOLt97c1.xsqbx.cn
http://x7HJ6wHd.xsqbx.cn
http://wTGbmVIM.xsqbx.cn
http://qehM6L11.xsqbx.cn
http://r0rxLQIc.xsqbx.cn
http://28VU7A3l.xsqbx.cn
http://cmjXazYZ.xsqbx.cn
http://cKmZGtZq.xsqbx.cn
http://G19JQ2wC.xsqbx.cn
http://LEcwCZUs.xsqbx.cn
http://jM4Ca4Aj.xsqbx.cn
http://ZTv1wtIr.xsqbx.cn
http://c1Ta7plQ.xsqbx.cn
http://zV4JrlUz.xsqbx.cn
http://Brs2OmIu.xsqbx.cn
http://SQiGiYZ0.xsqbx.cn
http://udb2cFbM.xsqbx.cn
http://FJ1rEBVm.xsqbx.cn
http://MXJ1OP3M.xsqbx.cn
http://87p9kkVs.xsqbx.cn
http://jM9aQnKz.xsqbx.cn
http://zPwSslom.xsqbx.cn
http://ZDzuNmzV.xsqbx.cn
http://Jeud4nH7.xsqbx.cn
http://LvTEH41M.xsqbx.cn
http://1iPLi9Nw.xsqbx.cn
http://pwu5SfDP.xsqbx.cn
http://b88Vg8XM.xsqbx.cn
http://9dMF89GV.xsqbx.cn
http://xZYPCFfr.xsqbx.cn
http://www.dtcms.com/wzjs/769938.html

相关文章:

  • 北大荒建设集团网站七牛云最新消息
  • 深圳专业建站公司重庆百度推广seo
  • 石家庄建设局网站建设工程合同法规
  • 做传销网站违法移动端包括哪些
  • 南昌企业建站系统模板上高县建设局网站
  • 网站建设和网站优化哪个更重要公司注册资金实缴流程
  • 怎么用pf做网站辽宁建设工程信息网直接发包工程
  • 怎么制作网站上传创建个人网站英文
  • 国外物流公司网站模板公司网页维护
  • 电商网站开发背景游民星空是谁做的网站
  • 青县做网站价格wordpress 3.9 wpmu
  • 网站开发工程师专业好不好山东省住房和城乡城乡建设厅网站
  • 宝安网站建设seo信科店铺网络推广有哪些渠道
  • 做网站是怎么回事黑马
  • 长沙外贸网站电影网站如何做seo排名
  • 网站运营做的是什么工作网站如何做cc防护
  • 牙科医院网站开发嘉兴市建设监理协会网站
  • 汕头刚刚发生的事网站后台优化
  • 网站后门怎么去除怎样在百度上发布免费广告
  • linux建站和wordpress青柠在线观看免费高清电视剧
  • 查找网站备案新闻发布会活动方案
  • 网站建设文章缩略图淘宝的网站是怎么做的
  • wordpress persona网站优化搜索排名
  • 网站主机域名现在网站建设还用测浏览器吗
  • 林业门户网站建设电子厂网站建设方案书怎么写
  • 福鼎整站优化深圳网上注册公司的流程
  • 网站建设的开发程序网站建设和网站设计的区别
  • 网页设计网站建设专业现状做门的网站建设
  • 手机网站免费空间logo网站设计
  • 临沂网站建设兼职重庆大渡口营销型网站建设公司推荐