Spring Boot actuator

Reading material

https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html

Prometheus

https://docs.spring.io/spring-boot/api/rest/actuator/prometheus.html

Definition of Actuator

An actuator is a manufacturing term that refers to a mechanical device for moving or controlling something. Actuators can generate a large amount of motion from a small change.

Enabling Actuator

The spring-boot-actuator module provides all of Spring Boot’s production-ready features. The recommended way to enable the features is to add a dependency on the spring-boot-starter-actuator “Starter”.

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

Endpoints

https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints

The full list of endpoints available for the project is visible in application logs during startup. But you should see this in the list: http://localhost:8080/actuator and that should show you all the other actuator endpoints available for the application.

The /info endpoint does not provide any information by default. If you want to change this, you need to use one of the three available auto-configured InfoContributor beans or write your own.

  1. EnvironmentInfoContributor exposes environment keys in the endpoint.
  2. GitInfoContributor detects the git.properties file in the classpath and then displays all necessary information about commits, such as branch name or commit ID.
  3. BuildInfoContributor gathers information from the META-INF/build-info.properties file and also displays it in the endpoint.

The two properties files for Git and build information can be automatically generated during application build. To achieve this, you should include git-commit-id-plugin in your pom.xml and customize spring-boot-maven-plugin to generate build-info.properties in the way visible in this code fragment:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>build-info</goal>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <additionalProperties>
                    <java.target>${maven.compiler.target}</java.target>
                    <time>${maven.build.timestamp}</time>
                </additionalProperties>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>pl.project13.maven</groupId>
    <artifactId>git-commit-id-plugin</artifactId>
    <configuration>
        <failOnNoGitDirectory>false</failOnNoGitDirectory>
    </configuration>
</plugin>

With the build-info.properties file available, your /info would be a little different than before:

{
    "build": {
        "version":"1.0-SNAPSHOT",
        "java": {
            "target":"1.8"
        },
        "artifact":"sample-spring-boot-web",
        "name":"sample-spring-boot-web",
        "group":"pl.piomin.services",
        "time":"2017-10-04T10:23:22Z"
    }
}

Links to this note