Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Prometheus Health Check
package de.mafr.demo.prometheus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import io.micrometer.prometheus.PrometheusMeterRegistry;
public class PrometheusDemoApplication {
private HealthEndpoint healthEndpoint;
@Bean MeterRegistryCustomizer prometheusHealthCheck() {
return registry -> registry.gauge("health", healthEndpoint, ep -> healthToCode(ep));
private static int healthToCode(HealthEndpoint ep) {
Status status =;
return status.equals(Status.UP) ? 1 : 0;
public static void main(String[] args) {, args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment