Springboot之Actuator的使用解析

简介: 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
}
相关文章
|
1月前
|
缓存 前端开发 Java
【二十八】springboot之通过threadLocal+参数解析器实现同session一样保存当前登录信息的功能
【二十八】springboot之通过threadLocal+参数解析器实现同session一样保存当前登录信息的功能
32 1
|
2天前
|
JSON Java Maven
Javaweb之SpringBootWeb案例之 SpringBoot原理的详细解析
Javaweb之SpringBootWeb案例之 SpringBoot原理的详细解析
7 0
Javaweb之SpringBootWeb案例之 SpringBoot原理的详细解析
|
2天前
|
存储 Java 程序员
SpringBoot之分层解耦以及 IOC&DI的详细解析
SpringBoot之分层解耦以及 IOC&DI的详细解析
5 0
|
2天前
|
前端开发 Java
SpringBoot之三层架构的详细解析
SpringBoot之三层架构的详细解析
13 0
|
2天前
|
前端开发 Java
SpringBoot之实体参数的详细解析
SpringBoot之实体参数的详细解析
10 0
|
2天前
|
Web App开发 前端开发 Java
SpringBoot之请求的详细解析
SpringBoot之请求的详细解析
12 0
|
1月前
|
SQL Java 数据库连接
springboot解析txt文件顺便加到数据库中(nohup文件)
springboot解析txt文件顺便加到数据库中(nohup文件)
112 1
|
7天前
yolo-world 源码解析(六)(2)
yolo-world 源码解析(六)
18 0
|
7天前
yolo-world 源码解析(六)(1)
yolo-world 源码解析(六)
12 0
|
8天前
yolo-world 源码解析(五)(4)
yolo-world 源码解析(五)
19 0

推荐镜像

更多