Springboot之Actuator的使用解析

本文涉及的产品
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
全局流量管理 GTM,标准版 1个月
云解析 DNS,旗舰版 1个月
简介: Springboot之Actuator的使用解析Actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、相关功能统计等。

Springboot之Actuator的使用解析

Actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、相关功能统计等。

1.准备环境:

一个springBoot工程

2.添加依赖:

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

3.可以在你的application.yml配置文件配置:

注意:在properties文件中配置actuator权限配置(否则访问一些暴露的监控信息会报401,很多博客里没有这一项,让很多人误解了)

management.security.enabled=false 
#信息
info:
  contact:
    email: test
    phone: test
##运行状态 actuator监控
endpoints:
  enabled: true
  info:
    sensitive: false
  health:
    sensitive: false
management:
  ##服务路径
  context-path: /
  security:
    enabled: false
  ##服务端口
  port: 8081

如果你使用application.properties,可以做类似的配置:

endpoints.enabled=true
endpoints.info.sensitive=false
endpoints.health.sensitive=false
management.context-path=/
management.port=8081

4.接口

接口 描述 敏感
actuator 列出所有可用接口 true
autoconfig 显示一个auto-configuration的报告,该报告展示所有auto-configuration候选者及它们被应用或未被应用的原因 true
beans 显示一个应用中所有Spring Beans的完整列表 true
configprops 显示一个所有@ConfigurationProperties的整理列表 true
dump 显示当前应用线程状态信息 true
env 显示Spring的ConfigurableEnvironment属性 true
health 展示应用的健康信息(当使用一个未认证连接访问时显示一个简单的’status’,使用认证连接访问则显示全部信息详情) false
info 显示应用信息 false
metrics 展示当前应用的’指标’信息 true
mappings 显示一个所有@RequestMapping路径的整理列表 true
shutdown 允许应用以优雅的方式关闭(默认情况下不启用) true
trace 显示trace信息(默认情况下是最后100个HTTP请求) true
loggers 提供显示和修改应用程序中loggers配置的功能 true

5.访问结果示例

/health

{
  status: "UP",
  diskSpace: {
    status: "UP",
    total: 472446402560,
    free: 465802993664,
    threshold: 10485760
  },
  redis: {
    status: "UP",
    version: "3.2.100"
  },
  db: {
    status: "UP",
    database: "MySQL",
    hello: 1
  }
}

/info

{
contact: {
    email: "test",
    phone: "test"
}
}

/metrics

{
  mem: 614490,
  mem.free: 238291,
  processors: 4,
  instance.uptime: 51601,
  uptime: 56528,
  systemload.average: -1,
  heap.committed: 556032,
  heap.init: 131072,
  heap.used: 317740,
  heap: 1857024,
  nonheap.committed: 59968,
  nonheap.init: 2496,
  nonheap.used: 58459,
  nonheap: 0,
  threads.peak: 42,
  threads.daemon: 36,
  threads.totalStarted: 59,
  threads: 38,
  classes: 7991,
  classes.loaded: 7991,
  classes.unloaded: 0,
  gc.ps_scavenge.count: 8,
  gc.ps_scavenge.time: 219,
  gc.ps_marksweep.count: 2,
  gc.ps_marksweep.time: 86,
  httpsessions.max: -1,
  httpsessions.active: 0,
  datasource.primary.active: 0,
  datasource.primary.usage: 0,
  gauge.response.info: 47,
  gauge.response.star-star.favicon.ico: 19,
  counter.status.200.info: 1,
  counter.status.200.star-star.favicon.ico: 1
}
相关文章
|
12天前
|
前端开发 数据可视化 Java
SpringBoot的4中常见入参形式错误解析
在使用SpringBoot进行前后端接口对接时,常遇到如500、400等请求错误,本文总结了四个常见的复杂请求类型及其解决方案,包括实体嵌套List提交、普通文件上传、List提交及数组Array提交,详细展示了正确的前端与后端代码实现,帮助开发者避免常见错误,提高开发效率。
22 0
SpringBoot的4中常见入参形式错误解析
|
2月前
|
Java Spring 容器
Spring Boot 启动源码解析结合Spring Bean生命周期分析
Spring Boot 启动源码解析结合Spring Bean生命周期分析
78 11
|
17天前
|
XML Java 应用服务中间件
SpringBoot启动流程解析
SpringBoot启动流程解析
24 0
|
2月前
|
监控 安全 Java
解析Spring Boot中的Actuator端点
解析Spring Boot中的Actuator端点
|
2月前
|
Java Spring
解析Spring Boot中的配置文件与外部化配置
解析Spring Boot中的配置文件与外部化配置
|
2月前
|
Java Spring
解析Spring Boot中的事务管理机制
解析Spring Boot中的事务管理机制
|
3月前
|
JSON 缓存 Java
Spring Boot中的JSON解析优化
Spring Boot中的JSON解析优化
|
3月前
|
Java 测试技术 应用服务中间件
Spring 与 Spring Boot:深入解析
Spring 与 Spring Boot:深入解析
29 0
|
3月前
|
监控 Java 开发者
Spring Boot 3 升级全解析:新特性与改进点一网打尽
Spring Boot 3 升级全解析:新特性与改进点一网打尽
|
13天前
|
监控 网络协议 Java
Tomcat源码解析】整体架构组成及核心组件
Tomcat,原名Catalina,是一款优雅轻盈的Web服务器,自4.x版本起扩展了JSP、EL等功能,超越了单纯的Servlet容器范畴。Servlet是Sun公司为Java编程Web应用制定的规范,Tomcat作为Servlet容器,负责构建Request与Response对象,并执行业务逻辑。
Tomcat源码解析】整体架构组成及核心组件

推荐镜像

更多