
de.marcoaust.prometheus.PrometheusConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-prometheus Show documentation
Show all versions of spring-boot-prometheus Show documentation
Spring-Boot-Prometheus makes it easy to use Prometheus with Spring Boot. It exposes an /prometheus
endpoint with prometheus-compatible metrics just by adding @EnablePrometheusEndpoint to your configuration.
The newest version!
package de.marcoaust.prometheus;
import java.util.Collection;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.hotspot.DefaultExports;
import org.springframework.boot.actuate.endpoint.PublicMetrics;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
class PrometheusConfiguration {
private CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry;
@Bean
public SpringBootMetricsCollector springBootMetricsCollector(Collection publicMetrics) {
SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector(publicMetrics);
springBootMetricsCollector.register(collectorRegistry);
return springBootMetricsCollector;
}
@Configuration
@ConditionalOnClass(DefaultExports.class)
@ConditionalOnProperty(prefix = "prometheus.hotspot", name = "enabled", matchIfMissing = true)
static class HotspotMetricsExporter {
public HotspotMetricsExporter() {
DefaultExports.initialize();
}
}
@Bean
public PrometheusEndpoint prometheusEndpoint() {
return new PrometheusEndpoint(collectorRegistry);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy