Enable Spring Boot Actuator

This feature is available since Bloomreach Experience Manager 14.6.0

Introduction

Goal

Enable Spring Boot Actuator in an implementation project's CMS application in order to access additional monitoring and management features.

Background

Since version 14.6, Spring Boot framework has been integrated into the CMS application, adding support for a number of additional features to help in monitoring and managing the CMS application when it is pushed to production. The CMS application can be managed and monitored through HTTP endpoints or JMX by leveraging Spring Boot Actuator.

This page explains how to enable Spring Boot Actuator in the CMS application.

Prerequisites

To use this feature, your implementation project must use Bloomreach Experience Manager version 14.6.0 or later.

Instructions

Add Maven dependencies

Open cms-dependencies/pom.xml and add the following dependencies:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <version>${spring-boot.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
      <version>1.5.5</version>
    </dependency>
    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-jmx</artifactId>
      <version>1.5.5</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
Please note that spring-boot-starter-logging and slf4j-api dependencies should be excluded.

The dependencies above add support for Spring Boot Actuator and the Micrometer framework.

Create Spring Boot configuration

In the CMS module, create a new file src/main/java/org/bloomreach/xm/cms/ActuatorConfiguration.java with the following contents:

package org.bloomreach.xm.cms;

import javax.naming.NamingException;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jndi.JndiObjectFactoryBean;

@Configuration
@PropertySource(value = "classpath:actuator.properties")
public class ActuatorConfiguration {

    @Value("${app.datasource.name}")
    String datasourceName;

    @Bean(destroyMethod = "")
    DataSource jndiDataSource() throws IllegalArgumentException, NamingException {
        final JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
        bean.setJndiName("java:comp/env/jdbc/" + datasourceName);
        bean.afterPropertiesSet();
        return (DataSource) bean.getObject();
    }

    @Bean
    HealthIndicator dbHealthIndicator(final DataSource dataSource) {
        return new DataSourceHealthIndicator(dataSource, "SELECT 1");
    }

}
@PropertySource(value = "classpath:actuator.properties") points to the property file which contains additional configuration.
Any Java-based configuration located at org.bloomreach.xm.cms will be auto located and used by Spring Boot due to framework conventions.

Create properties File

Create a new file src/main/resources/actuator.properties with the following contents:

management.endpoint.health.probes.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

app.datasource.name=actuatorDS

The sample configuration above enables health probes and exposes all actuator's endpoints. For further information please refer to Spring Boot Actuator documentation.

Create a datasource if not present

Please note that app.datasource.name property should point to a JNDI datasource name used in your CMS setup, typically a <Resource> element in context.xml.
When running on Bloomreach Cloud, please reuse the repository datasource named "repositoryDS".

For running locally with Cargo, it's easiest to use an H2 database.

<Resource name="jdbc/actuatorDS" auth="Container" type="javax.sql.DataSource"
     maxTotal="100" maxIdle="10" initialSize="10" maxWaitMillis="10000"
     testWhileIdle="true" testOnBorrow="false" validationQuery="SELECT 1"
     timeBetweenEvictionRunsMillis="10000"
     minEvictableIdleTimeMillis="60000"
     username="sa" password=""
     driverClassName="org.h2.Driver"
     url="jdbc:h2:${repo.path}/brxm/actuator"/>

Rebuild and start the project using cargo profile

Rebuild and start the project.

Access http://localhost:8080/cms/actuator. You should see Spring Boot Actuator based page.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?