如何 create/customize Spring 启动执行器以公开我的 Camunda 应用程序的应用程序健康检查和诊断?

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

有人要求我为我的 Camunda Engine/BPMN 工具创建 Spring 引导执行器。这样我们就可以通过 SpringActuator.

公开各种应用程序健康检查和诊断

这应该被扩展以公开 Camunda 的运行状况、配置和指标。知道如何进行吗?

假设您使用的是 camunda spring 引导启动器:启动器中包含 ProcessEngine 和 JobExecutor 的两个默认健康指标,请查看:

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));
  }

这应该会让您了解如何实施 springs AbstractHealthIndicator、访问 camunda 组件并使用它们进行健康检查。

我已经能够自定义现有的健康检查执行器。为想要在项目中自定义的人分享下面的代码。

@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();
    }

}