spring boot actuator基本配置

1.5.3版本官方doc

spring-boot-actuator包自动提供了默认的management endpoint,用以监控容器内部的各种状态和指标。

import

dependencies {
	compile("org.springframework.boot:spring-boot-starter-actuator")
}

打开endpoints

endpoints默认状态就是打开的。如果想全部关掉,然后分别打开:

management:
  context-path: /actuator
  security:
    enabled: false
endpoints:
  enabled: false
  health:
    enabled: true
    time-to-live: 10000
  info:
    enabled: true

关于security

如果系统没有@EnableWebSecurity自行定制security的话,可以使用management.security.enabled来控制management endpoint中sensitive的访问权限,以及not sensitive的显示内容范围。如下:

management:
  context-path: /actuator
  security:
    enabled: true
security:
  basic:
    enabled: true
  user:
    name: admin
    password: secret

当@EnableWebSecurity后,所有访问权限都由WebSecurityConfigurerAdapter的子类full controll。

spring boot 1.4可以通过management.security.enabled=false来关闭对management endpoints的security check,是由于spring boot实现的一个bug。
spring boot 1.5中已经修复。
而在spring boot 2.0中已经将management.security.enabled去掉。
因此,在custom WebSecurityConfigurerAdapter中,还是使用正确的姿势对management endpoints进行特别设置:

...
.antMatchers("/info", "/health", "/metrics").permitAll()

关于management.port

management.port=9999虽然可以将management endpoint开放在独立的端口上,但/healthcheck并不能自动检测主端口是否可用。
因此,如果使用management.port时,可能需要自行定制一个HealthIndicator来ping主服务端口。

转载于:https://my.oschina.net/elleneye/blog/1826981

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值