简体   繁体   中英

Spring Boot 2 Actuator Micrometer setup

I have a Spring Boot Application and I have this dependency:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
  <version>2.1.7.RELEASE</version> // From Parent
</dependency>

I have also configured my application.yml file to expose metrics:

management:
  endpoints:
    web:
      exposure:
        include: info, health, metrics

I have also created a Metrics bean for Kafka:

@Bean
public KafkaConsumerMetrics kafkaConsumerMetrics() {
  return new KafkaConsumerMetrics();
}

But when I hit the endpoint GET http://localhost:8080/actuator/metrics I get a 404 Page Not Found error.

The other endpoints (info/health) works: http://localhost:8080/actuator/info and http://localhost:8080/actuator/health

What am I missing to get micrometer data?

you can try enabling metrics from the configuration, though it should be enabled by default

management:
  endpoint:
    metrics:
      enabled: true

More details on actuator properties https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#actuator-properties

For restricted endpoints like metrics, beans etc:

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

and in your yml:

management:
   security:
      enabled: true
security:
   basic:
      enabled: true

then a config class like:

@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

       auth.inMemoryAuthentication().withUser("admin").
          password("admin").roles("ADMIN");

       auth.inMemoryAuthentication().withUser("admin").
          password("admin").roles("ACTUATOR");
      }
   }

Then the restricted actuator endpoints are enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM