Method marked with @Timed is not a part of ConsoleReporter output

104 Views Asked by At

I try to implement simple sring boot application with dropwizard metrics

My codebase:

@SpringBootApplication
@EnableMetrics(proxyTargetClass = true)
public class DemoApplication {

    public static void main(String[] args) {
        MetricRegistry metricRegistry = new MetricRegistry();

        Meter meter = metricRegistry.meter("meter");
        meter.mark();
        meter.mark(200);
        ConsoleReporter reporter = ConsoleReporter.forRegistry(metricRegistry).build();
        reporter.start(5, TimeUnit.SECONDS);
        reporter.report();

        Counter counter = metricRegistry.counter("counter");
        counter.inc();
        counter.dec();

        SpringApplication.run(DemoApplication.class, args);
    }

}

@RestController
public class HelloController {
    private AtomicLong atomicLong = new AtomicLong();

    @GetMapping("/hello")
    @Timed
    public String index() {
        return "Greetings from Spring Boot!. count=" + atomicLong.incrementAndGet();
    }

}

build.gradle:

plugins {
    id 'org.springframework.boot' version '2.7.1'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    // Minimum required for metrics.
    implementation ('com.ryantenney.metrics:metrics-spring:3.1.3') {
        exclude group: 'com.codahale.metrics'
        exclude group: 'org.springframework'
    }
    implementation 'io.dropwizard.metrics:metrics-core:4.2.9'
    implementation 'io.dropwizard.metrics:metrics-annotation:4.2.9'
    implementation 'io.dropwizard.metrics:metrics-servlets:4.2.9'

    implementation 'io.prometheus:simpleclient_dropwizard:0.15.0'
    implementation 'io.prometheus:simpleclient_servlet:0.15.0'
    implementation 'io.dropwizard:dropwizard-core:2.1.0'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

This code produces following output to logs:

28.06.2022, 18:46:19 ===========================================================

-- Counters --------------------------------------------------------------------
counter
             count = 0

-- Meters ----------------------------------------------------------------------
meter
             count = 201
         mean rate = 5,69 events/second
     1-minute rate = 24,38 events/second
     5-minute rate = 36,37 events/second
    15-minute rate = 38,88 events/second

I don't see any mentiones of this endpoint calls. How can I fix it ?

 @GetMapping("/hello")
    @Timed
    public String index() {
        return "Greetings from Spring Boot!. count=" + atomicLong.incrementAndGet();
    }
0

There are 0 best solutions below