How to create/customize Spring Boot Actuators for exposing application healthchecks and diagnostics for my Camunda Application?

Viewed 577

I have been asked to create Spring Boot Actuators for my Camunda Engine/BPMN tool. SO that we can exposes various applications healthchecks and diagnostics via SpringActuator.

This should be extended to expose health, config and metrics for Camunda. Any idea how to proceed on this?

2 Answers

Assuming that you are using the camunda spring boot starter: Two default health indicators for ProcessEngine and JobExecutor are included with the starter, have a look at:

https://github.com/camunda/camunda-bpm-spring-boot-starter/tree/master/starter/src/main/java/org/camunda/bpm/spring/boot/starter/actuator

 @Override
  protected void doHealthCheck(Builder builder) throws Exception {
    boolean active = jobExecutor.isActive();
    if (active) {
      builder = builder.up();
    } else {
      builder = builder.down();
    }
    builder.withDetail("jobExecutor", Details.from(jobExecutor));
  }

which should give you an idea how to implement springs AbstractHealthIndicator, access camunda components and use them for health checks.

I have been able to customize the existing healthcheck actuator. Sharing the code below for people who want to customize in there projects.

@Component
public class X extends AbstractHealthIndicator {
    @Autowired
    public JobExecutor jobExecutor;

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        boolean active = jobExecutor.isActive();
        if (active) {
            builder = builder.up();
        } else {
            builder = builder.down();
        }
        builder.withDetail("jobExecutor", healthDetails(jobExecutor));
    }

    private Details healthDetails(JobExecutor jobExecutor) {
        final DetailsBuilder builder = Details.builder().name(jobExecutor.getName())
                .lockOwner(jobExecutor.getLockOwner()).lockTimeInMillis(jobExecutor.getLockTimeInMillis())
                .maxJobsPerAcquisition(jobExecutor.getMaxJobsPerAcquisition())
                .waitTimeInMillis(jobExecutor.getWaitTimeInMillis());

        for (ProcessEngineImpl processEngineImpl : jobExecutor.getProcessEngines()) {
            builder.processEngineName(processEngineImpl.getName());
        }

        return builder.build();
    }

}
Related