当我们决定用spring boot作为微服务框架时,除了它强大的快速开发功能之外,还因为它在starter POM中提供了一个特殊依赖模块spring-boot-starter-actuator。引入该模块能够自动为spring boot构建的应用提供一系列监控的端点。
初识actuator
在现有的Spring boot应用中引入该模块非常简单,只需在pom依赖中加入spring-boot-starter-actuator的依赖即可,具体如下:
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
配置
management.security.enabled=false
配置文件
git.properties
git.branch=
git.commit.id=
git.commit.time=
Actuator监控分成两类:原生端点和用户自定义扩展端点,原生的主要有:
路径 描述
/autoconfig 提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没通过
/beans 描述应用程序上下文里全部的Bean,以及它们的关系
/env 获取全部环境属性
/configprops 描述配置属性(包含默认值)如何注入Bean
/dump 获取线程活动的快照
/health 报告应用程序的健康指标,这些值由HealthIndicator的实现类提供
/info 获取应用程序的定制信息,这些信息由info打头的属性提供
/mappings 描述全部的URI路径,以及它们和控制器(包含Actuator端点)的映射关系
/metrics 报告各种应用程序度量信息,比如内存用量和HTTP请求计数
/shutdown 关闭应用程序,要求endpoints.shutdown.enabled设置为true
/trace 提供基本的HTTP请求跟踪信息(时间戳、HTTP头等)