Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Minimal example on how to setup Spring Boot with Prometheus

What to expect

Run a Spring Boot application an read metrics from JVM and annotated application methods using a Prometheus endpoint.


This is a working example for a minimal Spring-Boot 2.0.x app using

How to Run

To run with maven

mvn compile spring-boot:run

Open http://localhost:8080 to issue calls to be counted and to access the metrics.

Key bits and pieces

  1. Add Micrometer to the projects. Add Actuator starter to let the autoconfiguration create a Prometheus metrics endpoint.

  2. Configure some specifics
    public class MetricsApplicationConfig {
        // as of now, this aspect needs to be created manually, see
        public TimedAspect timedAspect(MeterRegistry registry) {
            return new TimedAspect(registry);
        public MetricsApplicationConfig(PrometheusMeterRegistry prometheusMeterRegistry) {
            // add existing Prometheus modules as needed
            new MemoryPoolsExports().register(prometheusMeterRegistry.getPrometheusRegistry());
            new GarbageCollectorExports().register(prometheusMeterRegistry.getPrometheusRegistry());
            new VersionInfoExports().register(prometheusMeterRegistry.getPrometheusRegistry());
  3. Collect application metrics at specific methods
    @Timed(histogram = true) // customize this to use a histogram
    public String countedCall() throws InterruptedException {
        /* ... */
        return "waited: " + delay + " ms";
    @Timed(value = "doSomething", description = "this is doing something")
    public void doSomething() {"hi");