Reputation: 41
I‘m looking for a way to change the header (add some things to it) of the health check of spring boot. I searched for this topic but I only found questions about custom health functions and so on (e.g. How to add a custom health check in spring boot health?). That‘s not what I am looking for.
I want to use the standard/default health function (so I don‘t want to change the body of the response („status“:“UP“) nor do I want to implement my own health functionality or customize the default one. My goal is to change the header of the response in order to achieve two things:
Is there any way to use the default health check and just modify the header and the properties like allowed origin or do I have to create a new controller?
Thanks for your help.
Upvotes: 4
Views: 505
Reputation: 4613
Just implement your own service with the methods getting the adequate metrics, and then of course your custom controller refering to it. I don't think you can modify those default endpoints..
Here's an example of this custom service:
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.MetricsEndpoint;
import org.springframework.stereotype.Component;
@Component
public class SpringActuator {
@Autowired
MetricsEndpoint metrics;
public Double getCPU() {
return metrics.metric("process.cpu.usage", Arrays.asList()).getMeasurements().get(0).getValue();
}
public Double getRAM() {
return metrics.metric("jvm.memory.used", Arrays.asList()).getMeasurements().get(0).getValue();
}
}
Upvotes: 1