简体   繁体   中英

Custom Metrics for Actuator Prometheus

I have activated the spring actuator prometheus endpont /actuator/prometheus . By adding the dependencies for micrometer and actuator and enabled prometheus endpont. How can i get there custom metrics?

You'll need to register your metrics with the Micrometer Registry.

The following example creates the metrics in the constructor. The Micrometer Registry is injected as a constructor parameter:

@Component
public class MyComponent {

    private final Counter myCounter;

    public MyComponent(MeterRegistry registry) {
        myCounter = Counter
                .builder("mycustomcounter")
                .description("this is my custom counter")
                .register(registry);
    }

    public String countedCall() {
        myCounter.increment();
    }
}

Once this is available, you'll have a metric mycustomcounter_total in the registry available in the /prometheus URL. The suffix "total" is added to comply with the Prometheus naming conventions.

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