how to add health path dynamically to spring actuator - Stack Overflow

admin2025-04-25  5

How do I add multiple paths to management.endpoint.health.group.liveness.additional-path ?

I tried with server:/somehealth,server:/another and with server:/somehealth;server:/anotherhealth

final var app = new SpringApplication();
app.setDefaultProperties(createConfigMap());
app.run();
protected HashMap<String, Object> createConfigMap() {
    var configMap = new HashMap<String, Object>(Map.ofEntries(
            Map.entry("management.endpoints.web.base-path", "/"),
            Map.entry("management.endpoints.web.exposure.include", "health,prometheus,info"),
            Map.entry("management.endpoints.web.path-mapping.prometheus", "metrics"),
            Map.entry(
                    "management.endpoint.health.group.readiness.additional-path", "server:/ready"),
            Map.entry("management.health.probes.enabled", "true")));

    for (var path: _config.getAdditionalHealthPaths().stream().map(path -> String.format("server:%s", path)).toList()) {
      configMap.put("management.endpoint.health.group.liveness.additional-path", path);
    }

    return configMap;
  }

Is there a way to add dynamically new paths to the health endpoint?

I would not like to use @RequestMapping("path") since I don't know beforehand which might be the paths to add to the liveness for example.

Do I need to write a RestController to add these new paths?

How do I add multiple paths to management.endpoint.health.group.liveness.additional-path ?

I tried with server:/somehealth,server:/another and with server:/somehealth;server:/anotherhealth

final var app = new SpringApplication();
app.setDefaultProperties(createConfigMap());
app.run();
protected HashMap<String, Object> createConfigMap() {
    var configMap = new HashMap<String, Object>(Map.ofEntries(
            Map.entry("management.endpoints.web.base-path", "/"),
            Map.entry("management.endpoints.web.exposure.include", "health,prometheus,info"),
            Map.entry("management.endpoints.web.path-mapping.prometheus", "metrics"),
            Map.entry(
                    "management.endpoint.health.group.readiness.additional-path", "server:/ready"),
            Map.entry("management.health.probes.enabled", "true")));

    for (var path: _config.getAdditionalHealthPaths().stream().map(path -> String.format("server:%s", path)).toList()) {
      configMap.put("management.endpoint.health.group.liveness.additional-path", path);
    }

    return configMap;
  }

Is there a way to add dynamically new paths to the health endpoint?

I would not like to use @RequestMapping("path") since I don't know beforehand which might be the paths to add to the liveness for example.

Do I need to write a RestController to add these new paths?

Share Improve this question asked Jan 16 at 7:36 Jhonny Knaak de VargasJhonny Knaak de Vargas 1
Add a comment  | 

1 Answer 1

Reset to default 0

This is not supported, only a single additional path is allowed.

Health groups can be made available at an additional path on either the main or management port. This is useful in cloud environments such as Kubernetes, where it is quite common to use a separate management port for the actuator endpoints for security purposes.

This property is bound to AdditionalHealthEndpointPath which accepts a single value.

转载请注明原文地址:http://anycun.com/QandA/1745547164a90909.html