Micrometer: Webflux monitoring with micrometer in Spring Boot 2

Created on 8 Nov 2017  路  14Comments  路  Source: micrometer-metrics/micrometer

Currently, I'm playing with Spring Boot 2 and would like to profile the application with micrometer. The project is built with Spring boot 2.0.0.M6 and webflux. Though, I have an issue with integration of micrometer.

  1. https://docs.spring.io/spring-boot/docs/2.0.0.M6/reference/html/production-ready-metrics.html#production-ready-metrics-web-flux
  2. https://micrometer.io/docs/ref/spring/2.0

I've created a simple demo project for reference https://github.com/cyrillk/demo-spring-boot-metrics

dependencies

    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-webflux')
    compile group: 'io.micrometer', name: 'micrometer-core', version: '1.0.0-rc.3'

application.properties

endpoints.auditevents.enabled=true
endpoints.autoconfig.enabled=true
endpoints.beans.enabled=true
endpoints.configprops.enabled=true
endpoints.env.enabled=true
endpoints.health.enabled=true
endpoints.info.enabled=true
endpoints.loggers.enabled=true
endpoints.metrics.enabled=true
endpoints.mappings.enabled=true
endpoints.status.enabled=true
endpoints.threaddump.enabled=true
endpoints.trace.enabled=true
endpoints.logfile.enabled=true

server.port=8888

code sample

@RestController
public class DumbController {

    @Autowired
    private MeterRegistry meter;

    @GetMapping("/hello")
    public Mono<String> handle() {
        return Flux.range(0, 65536)
                .map(this::calculate)
                .flatMap(this::calculateOther)
                .count().map(Object::toString);
    }

    @Timed("calculate.plain.timed")
    @Scheduled
    private String calculate(int n) {

        meter.counter("calculate.plain.explicit").increment();

        return String.valueOf(tan(atan(tan(atan(n)))));
    }

    @Timed("calculate.reactive.timed")
    @Scheduled
    private Mono<String> calculateOther(String n) {

        meter.counter("calculate.reactive.explicit").increment();

        return Mono.just(n + "111");
    }
}

But, I can see only meter.counter("....") metrics when I open /application/metrics. @Timed annotations are never in there.

What could be the issue? Am I missing something?

Thank you in advance.

curl "localhost:8888/application/metrics" -s | jq
{
  "names": [
    "jvm.buffer.memory.used",
    "jvm.memory.used",
    "jvm.buffer.count",
    "logback.events",
    "process.uptime",
    "jvm.memory.committed",
    "system.load.average.1m",
    "calculate.reactive.explicit",
    "jvm.buffer.total.capacity",
    "jvm.memory.max",
    "http.server.requests",
    "process.start.time",
    "calculate.plain.explicit",
    "cpu"
  ]
}
spring-boot change

Most helpful comment

@jkschneider:
In order to make my annotation-metric accessible via e.g. http://localhost:8080/actuator/metrics/my.metric.name and given following simple Webflux-Controller ...

@RestController
public class DumbController {
    @GetMapping("/index")
    @Timed("my.metric.name")
    Mono<String> index() {
        return Mono.just("asdf");
    }
}

... I had to add spring-boot-starter-web to my build.gradle as well. Otherwise, the metric defined via annotation would not show up in /actuator/metrics

//spring-boot-version: 2.0.0.RELEASE
//micrometer: 1.0.1
dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-webflux')

    //Needed for metrics?
    compile('org.springframework.boot:spring-boot-starter-web')
}

spring-boot-version: 2.0.0.RELEASE
micrometer: 1.0.1

My question: Is that intentional or should the annotation-based metrics also work without spring-boot-starter-web?

All 14 comments

Thanks for the test. We just haven't gotten around to it yet ;). I expect this will be part of rc4 this Friday.

Great! ) I look forward to trying the new version.

@jkschneider Just to give you a heads up. Metrics seem to work for webflux reactive components for micrometer version 1.0.0-rc.7 and Spring Boot version 2.0.0.M7!

@cyrillk Heads up -- I think there are some other compatibility issues with Micrometer 1.0.0-rc.7 and Boot 2.0.0.M7. I suggest you upgrade to a Boot 2 snapshot if you want to use rc7.

Ok. Thank you!

Running into the same issue w/ Spring boot 2.0.0.M6

compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'

brings in io.micrometer:micrometer-core:1.0.0-rc.3 transitively

I have endpoints.metrics.enabled: true set in application.yml

going to /application/metrics shows all of the default metrics, but not any of the ones that I have explicitly requested through the use of the @Timed annotation from micrometer.

Am I missing something? I'd prefer to not have to upgrade to M7 right now.

@lunias Are you talking about @Timed on endpoints or just arbitrary methods?

Arbitrary methods, but ones that are invoked from outside their containing class. I'm used to dropwizard metrics and figured that @Timed was roughly analogous in both libraries? Bad assumption?

@lunias Bad assumption _today_, but #361. Originally we were trying to avoid the surprise of timings that stop working when AOP isn't present, but this feature is so commonly requested that I think it's unavoidable.

Alrighty! Thanks for the clarification. I'll keep an eye on #361

@jkschneider:
In order to make my annotation-metric accessible via e.g. http://localhost:8080/actuator/metrics/my.metric.name and given following simple Webflux-Controller ...

@RestController
public class DumbController {
    @GetMapping("/index")
    @Timed("my.metric.name")
    Mono<String> index() {
        return Mono.just("asdf");
    }
}

... I had to add spring-boot-starter-web to my build.gradle as well. Otherwise, the metric defined via annotation would not show up in /actuator/metrics

//spring-boot-version: 2.0.0.RELEASE
//micrometer: 1.0.1
dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-webflux')

    //Needed for metrics?
    compile('org.springframework.boot:spring-boot-starter-web')
}

spring-boot-version: 2.0.0.RELEASE
micrometer: 1.0.1

My question: Is that intentional or should the annotation-based metrics also work without spring-boot-starter-web?

Same issue as @kleino, is it possible to get the metric from @Timed with spring-boot-starter-webflux only please?

Thank you

A closed issue is not the best place to get support. You do not need to add the @Timed annotation to Spring Controllers when using the auto-configured Spring Boot support for Micrometer - Controller endpoints will automatically be timed with the http.server.requests meter name. This is documented in the Spring Boot documentation. If the intention is to use a different meter name for one WebFlux endpoint, it would be best to ask the Spring Boot team about such a feature, perhaps on their Gitter channel. Spring Boot 2 support of Micrometer lives in Spring Boot itself, not in this repository. Regarding using @Timed with Spring managed beans, see https://github.com/micrometer-metrics/micrometer/issues/361#issuecomment-366828104.

Many thanks for the comment @shakuzen

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samanthacatania picture samanthacatania  路  4Comments

wilkinsona picture wilkinsona  路  3Comments

alecharp picture alecharp  路  4Comments

nugnoperku picture nugnoperku  路  4Comments

ITman1 picture ITman1  路  4Comments