SpringCloud整合Prometheus出现问题解决

环境:
SpringBoot 2.2.5.RELEASE,SpringCloud Hoxton.SR5

依赖:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

启动类中添加以下bean

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }

yml文件配置:

# prometheus相关
management:
  endpoints:
    web:
      exposure:
        include:  '*'
      #注意此处使用,访问的时候必须访问/actuator/prometheus,如不配置则访问/prometheus
      base-path: /actuator

  metrics:
    tags:
      application: ${spring.application.name}

问题一:添加了依赖以后,无论是访问swagger还是 /actuator/prometheus会出现login,这是因为security的原因
解决办法:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)// 控制@Secured权限注解
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        /**
         * 所有都能訪問,放棄判斷權限
         */
        http.requestMatcher(EndpointRequest.toAnyEndpoint())
                .authorizeRequests((requests) -> requests.anyRequest().permitAll());

    }
}

问题二 出现 HttpMessageNotWritableException: No converter for [class java.lang.String]

解决办法很简单:

事情的原因是由于其他同事由于要解决long、bigint转json丢失精度
在WebMvcConfig中直接new MappingJackson2HttpMessageConverter对象,而它只支持MediaType.APPLICATION_JSON一种类型。

解决办法:
将丢失的mediaTypes类型都加进来。

@Configuration
class WebMvcConfig extends WebMvcConfigurationSupport {
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        StringHttpMessageConverter converter = new StringHttpMessageConverter();
        converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN));
        converters.add(converter);
	}
}

SpringBoot集成prometheus
springBoot或者springCloud 的集成 Prometheus监控-数据无法解析
如何解决这种情况下的Could not find acceptable representation
通过micrometer实时监控线程池的各项指标

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值