Επεξεργασία

Κοινή χρήση μέσω


Manage and monitor app with Spring Boot Actuator

Note

The Basic, Standard, and Enterprise plans will be deprecated starting from mid-March, 2025, with a 3 year retirement period. We recommend transitioning to Azure Container Apps. For more information, see the Azure Spring Apps retirement announcement.

The Standard consumption and dedicated plan will be deprecated starting September 30, 2024, with a complete shutdown after six months. We recommend transitioning to Azure Container Apps. For more information, see Migrate Azure Spring Apps Standard consumption and dedicated plan to Azure Container Apps.

This article applies to: ✅ Java ❎ C#

This article applies to: ✅ Basic/Standard ✅ Enterprise

Spring Boot Actuator brings production-ready features to your apps. You can effortlessly monitor your app, collect metrics, and understand the status or database activity with this tool. You gain access to professional-grade tools without needing to build them from scratch.

The actuator exposes vital operational data about your running application, like health status, metrics, information, and more. The actuator uses HTTP endpoints or Java Management Extensions (JMX), making it easy to interact with. After you integrate it, it provides several default endpoints, and like other Spring modules, it's easily configurable and extendable.

Azure Spring Apps uses the actuator for enriching metrics through JMX. It can also work with Application Live View in the Enterprise plan to help you get and interact with the data from apps.

Diagram that shows the data flow using Spring Boot Actuator.

Configure Spring Boot Actuator

The following sections describe how to configure the actuator.

Add actuator dependency

To add the actuator to a Maven-based project, add the following dependency:

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

This configuration works with any Spring Boot version because versions are covered in the Spring Boot Bill of Materials (BOM).

Configure actuator endpoint

By default, a Spring Boot application exposes the health endpoint only. To observe the configuration and configurable environment, use the following steps to enable the env and configprops endpoints as well:

  1. Go to app Overview pane, select Configuration in the setting menu, and then go to the Environment variables configuration page.

  2. Add the following properties as in the "key:value" form. This environment opens the following Spring Actuator endpoints: health, env, and configprops.

    management.endpoints.web.exposure.include: health,env,configprops
    
  3. Select Save. Your application restarts automatically and loads the new environment variables.

You can now go back to the app Overview pane and wait until the Provisioning Status changes to Succeeded.

To view all the endpoints built-in and related configurations, see the Exposing Endpoints section of Spring Boot Production-ready Features.

Secure actuator endpoint

When you open the app to the public, these actuator endpoints are exposed to the public as well. We recommend that you hide all endpoints by setting management.endpoints.web.exposure.exclude=*, because the exclude property takes precedence over the include property. This action blocks Application Live View in the Enterprise plan and other apps or tools that rely on the actuator HTTP endpoint.

In the Enterprise plan, there are two ways to secure the access:

  • You can disable the public endpoint of apps and configure a routing rule in VMware Spring Cloud Gateway to disable actuator access from the public. For more information, see Configure VMware Spring Cloud Gateway.

  • You can configure the actuator to listen on a different HTTP port from the main application. In a standalone application, the actuator HTTP port defaults to the same as the main HTTP port. For the application to listen on a different port, set the management.server.port property. The Application Live View is unable to automatically detect this port change, so you also need to configure the property on an Azure Spring Apps deployment. Then, the actuator isn't publically accessible, but the Application Live View can read from the actuator endpoint via another port. For more information, see Use Application Live View with the Azure Spring Apps Enterprise plan.

Next steps