Spring Boot Actuator- Web application monitoring made easy !!!!

Contents

  • What is spring boot actuator?
  • Enable actuator in spring boot application
  • What are actuator endpoints?
  • Enabling spring boot actuator endpoints
  • Actuator metrics endpoint

What is spring boot actuator?

Spring boot actuator module provides you the features which will help you monitor and manage your application. You can monitor your application status, gather various statistics related to CPU/memory usage, web requests etc., using spring boot actuator, without writing a single line of code.

How to enable actuator in spring boot application?

Enabling actuator in spring boot application is ridiculously simple. For a maven based application, just include below dependency in your pom.xml

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

Now, just re-deploy your application and start exploring spring boot actuator endpoints.

What are actuator endpoints?

Once above dependency is included, on application re-deployment, you will be provided with various endpoints through which actuator exposes details about the running application, like health, metrics, application info, thread-dump, env, etc. These endpoints can be exposed over HTTP.
By default, for all endpoints the default context path is /actuator

Below are the few built-in endpoints in Spring boot actuator

EndpointsDescription
/infoReturns static application information if added any
/envReturns list of properties in current environment
/healthReturns application health information.
/beansReturns a complete list of all the Spring beans in your application.
/mappingsReturns list of all the controller mappings in your application including actuator endpoints
/threaddumpIt performs a thread dump.
/metricsReturns list of metrics related to JVM memory used, system CPU usage and much more.
/metrics/{metric-name}Returns information/statistics related to given metric

Enabling spring boot actuator endpoints

By default, all the endpoints are enabled in actuator, but only two endpoints are exposed over http: /info and /health.

To enable any endpoint in actuator, follow below format to add property
management.endpoints.<endpoint-name>.enabled=true 
E.g. to enable health endpoint,

management.endpoints.health.enabled=true

To disable any endpoint in actuator,
management.endpoints.<endpoint-name>.enabled=false

management.endpoints.health.enabled=false

To expose any endpoints over http,
management.endpoints.web.exposure.include=<endpoint-name-1>,<endpoint-name-2>

management.endpoints.web.exposure.include=info, metrics

To expose all endpoints over http, you can use ‘*’ wildcard as below,

management.endpoints.web.exposure.include=*

To exclude some endpoints from being exposed over http,
management.endpoints.web.exposure.exclude=<endpoint-name>

management.endpoints.web.exposure.exclude=mappings

Additional properties

By default, /info endpoint returns empty response as there is no default application information available. To return custom application information, provide it in below format in your application.properties.
info.<property>=<property-value>
You can provide hierarchical information as well.

To return application name, version etc as info,

info.app.name=Spring Actuator Demo Application
info.app.description=This is actuator demo application with basic configuration
info.app.version=1.0.0

Above information results in below response from /info endpoint,

{
    "app": {
        "description": "Spring Actuator Demo Application",
        "version": "1.0.0",
        "name": "This is actuator demo application with basic configuration"
    }
}

By default, actuator endpoints are exposed on your application’s http port. To expose these endpoints using different port,

management.server.port=8090   

By default, base path for all endpoint is /actuator. It can be changed using below property,

management.endpoints.web.base-path = /manage

With above change, you should be able to access any actuator endpoint as
<your-server-hostname>/manage/<endpoint-name>

Actuator metrics endpoint

The /metrics endpoint is used to expose application statistics related to JVM memory usage, system CPU usage, web requests etc. Like any other endpoint, the /metrics endpoint can be exposed over http for use.

management.endpoints.web.exposure.include=info, health, metrics

By default, all metrics are enabled. You can view the list of metrics available through endpoint: /actuator/metrics
To disable metrics from being generated, add property in format below,
management.metrics.enable.<metric> = false

E.g. For disable metrics related to tomcat session,

mmanagement.metrics.enable.tomcat = false

You can view data related to one metric through endpoint: /actuator/metrics/<metric-name>
E.g. To view system uptime, execute /actuator/metrics/process.uptime. You will receive output in below format,

{
    "name": "process.uptime",
    "description": "The uptime of the Java virtual machine",
    "baseUnit": "seconds",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 605.497
        }
    ],
    "availableTags": []
}

Spring boot internally uses Micrometer as its metrics collector. Micrometer works as a facade for various monitoring tools like Prometheus, Influx, Graphite etc. All the metrics data collected by micrometer can be exported in the format which the monitoring system supports, via a dedicated endpoint.

I hope this article helps you to configure actuator in your spring boot application. Happy coding!!

Click here for demo application source code.

To learn more about spring boot actuator, refer this link.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.