Spring-Boot--Actuator

以上是官网对Actuator解释,大致意思就是:

当使用Actuator的时候SpringBoot包含一些额外的特性帮助你监控和管理你的应用。你可以选择HTTP端点或者JMX来管理监控你的应用。Auditing, health, and metrics 能够自动的应用的你的程序。

官方喊话了:Actuator是对你的应用程序进行管理和监控的,使用也非常方便,因为它可以自动的应用到你的程序。

Actuator使用

Actuator使用很简单,只需要在pom.xml文件中加入actuator依赖就可以了:

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

我们在管理监控我们的应用的时候需要使用Actuator提供给我们的端点来进行访问:http://{IP}:{端口}/actuator/{端点}

以上只是一个health端点的示例,在第一次使用的时候可能会发现以下结果:

这样的原因是因为2.x中heanlth默认细节是不会显示的。我们需要在配置文件yml中配置:

management:
    endpoint:
      health:
        show-details: always

上面只是使用一个示例来介绍怎么使用Actuator。下面罗列出Actuator所有的端点:

这些端点中SpringBoot只为我们暴露了health和info端点,如果要使用其他的端点需要在配置文件中配置:

management:
    endpoints:
        web:
          exposure:
            include:  "*"

我这样的配置是把所有的端点都暴露出来了。具体的可以查看官方文档https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#production-ready

需要注意一点的是shutdown这个端点,这个端点是用来让程序优雅停机。这个端点默认是不可用也不暴露的,我们需要通过配置文件将它开启并且暴露:

management:
    endpoints:
        web:
          exposure:
            include:  "*"
    endpoint:
      shutdown:
        enabled: true

使用post请求实现优雅停机

SpringBoot1.x和SpringBoot2.x还是有区别的,具体的需要查看官方文档,这里就不做陈述了。

猜你喜欢

转载自blog.csdn.net/u010994966/article/details/83061408