springboot endpoint actuator监控

springboot1.x 和2.x相比较:

1. 从上图中可以看出以 endpoints开头的都被移到management下面了

2. management.context-path已经被management.server.base-path给替换了

3. management.server.base-path要配合management.server.port才能起作用,单个设置没作用。

management.endpoints.web.base-path为web的根路径,此路径在management.server.port之下。默认为 /actuator

4. 通过web暴漏和排除暴漏的端口分别为: management.endpoints.web.exposure.include和

management.endpoints.web.exposure.exclude. 但是在暴漏之前需要启用具体的endpoint 比如启用bean是: management.endpoint.beans.enabled:true 。 不过默认的endpoint都是启用的,如果想改变默认不启用,需要用到配置:management.endpoints.enabled-by-default:false

5. management.health.default.enabled=false可以禁用健康监测

下面是yml配置文件的内容,路径是我测试随便填的

management:
  endpoints:
    web:
      exposure:
        include: '*'
      base-path: /ddd
      discovery:
        enabled: true
    enabled-by-default: true
  health:
    rabbit:
      enabled: false
    redis:
      enabled: false
    elasticsearch:
      enabled: false
  ##服务路径
  context-path: /abc
  security:
    enabled: false
  server:
#    port: 8888
    base-path: /ttt
  endpoint:
    beans:
      enabled: true
#    servlet:
#      context-path: /dfs
endpoints:
  actuator:
    path: /fff
    enabled: true

management.security.enabled

在springboot2.x中此配置已经废弃了,如果需要用户名和密码访问,是需要自己实现的

另外再springboot1.x中此配置可以根据用户是否授权来访问端点信息,不过若是再浏览器上想以输入账密的形式,则需要结合spring security来做

@Configuration
@EnableWebSecurity
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private Environment env;

    @Override
    public void configure(HttpSecurity httpSecurity) throws Exception {
        String contextPath = env.getProperty("management.context-path");
        if (StringUtils.isEmpty(contextPath)) {
            contextPath = "";
        }
        httpSecurity.csrf().disable();
        httpSecurity.authorizeRequests()
                .antMatchers("/**" + contextPath + "/**").authenticated()
                .anyRequest().permitAll()
                .and().httpBasic();
    }
}

这样就会实现下图所示效果:

未完待续、、、

参考的文章:Spring Boot 探索 | 服务监控与管理 Actuator_management.server.port-CSDN博客

spring boot 2.x 系列 —— actuator 服务监控与管理_springboot2.x监控端点配置 安全-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值