Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 572
Dullimeister Avatar asked May 18 '18 07:05

Dullimeister


1 Answers

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.

like image 154
ahus1 Avatar answered Nov 04 '22 20:11

ahus1