All Products
Search
Document Center

Application Real-Time Monitoring Service:Configure Micrometer for a Java application and use Managed Service for Prometheus to monitor it

Last Updated:Dec 04, 2024

This topic describes how to configure Micrometer for a Java application and use Alibaba Cloud Managed Service for Prometheus to monitor the application.

Prerequisites

A Java application is created.

Step 1: Configure Micrometer for the application

Note

A Spring Boot 2.x application is used as an example.

  1. Add the dependency of Spring Boot Actuator to the pom.xml file.

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
      <version>x.y.z</version>
    </dependency>
    Note

    To obtain the latest Maven project version, visit the Alibaba Cloud repository.

  2. Configure Spring Boot Actuator and add related configurations to the application.properties file to expose the port and endpoint that provide the monitoring data.

    management.server.port=8080
    management.endpoints.web.exposure.include=xxx, prometheus
  3. Add the Micrometer dependency to the pom.xml file of the Maven project.

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
      <version>x.y.z</version>
    </dependency>
    Note

    To obtain the latest Maven project version, visit the Alibaba Cloud repository.

  4. Add the Micrometer JVM Extras dependency to the pom.xml file.

    <dependency>
        <groupId>io.github.mweirauch</groupId>
        <artifactId>micrometer-jvm-extras</artifactId>
        <version>0.2.2</version>
    </dependency>
    Note

    To obtain the latest Maven project version, visit the Alibaba Cloud repository.

  5. Configure Micrometer JVM Extras. Add the following Spring beans to expose memory and thread metrics.

    /* With Spring */
    @Bean
    public MeterBinder processMemoryMetrics() {
        return new ProcessMemoryMetrics();
    }
    
    @Bean
    public MeterBinder processThreadMetrics() {
        return new ProcessThreadMetrics();
    }
  6. Deploy the application in an Alibaba Cloud Container Service for Kubernetes (ACK) cluster or an Elastic Compute Service (ECS) instance.

    Then, access the endpoint that provides the monitoring data and check whether the metrics are exposed. Sample endpoint: http://localhost:8080/actuator/prometheus. Port 8080 is used as an example. Replace it with the port number configured in the application.properties file.

    image

Step 2: Enable the Micrometer component

  1. Log on to the Application Monitoring Real-Time Monitoring Service (ARMS) console. In the left-side navigation pane, click Integration Center. On the page that appears, search for the Micrometer component.

    image

  2. On the Start Integration tab of the MicroMeter panel, configure the parameters and click OK.

    Parameter

    Description

    Select the environment type

    The environment in which the application is deployed. Valid values:

    • Kubernetes Environment

    • ECS(VPC)

    Select Cluster

    The ACK cluster in which the application is deployed. The parameter is available if the application is deployed in an ACK cluster.

    Labels

    The labels of the pod where Micrometer is deployed. We recommend that you use meaningful labels.

    Service Port

    The port of the application. The default port number is automatically filled in.

    Metrics Collection Path

    The endpoint that exposes the metrics. The default endpoint is automatically filled in.

    Use HTTPS to Collect Data

    By default, metric data is collected through the HTTP protocol. If you want to use HTTPS, turn on the switch.

    Metric Scrape interval (unit/second)

    The interval at which metric data is collected. Default value: 30.

Step 3: View the dashboards

  1. Log on to the ARMS console. In the left-side navigation pane, click Integration Management. On the Integrated Environments tab of the Integration Management page, click the name of the environment.

    image

  2. In the Addon Type section of the Component Management tab, click MicroMeter. Then, click Dashboards to view all the dashboard names.

    image

  3. Click the name of a dashboard.

    image

Step 4: Configure alerting

  1. In the Addon Type section of the Component Management tab, click MicroMeter. Then, click Alert Rule to view all the default alert rules.

  2. You can create alert rules based on your business requirements. For information about how to create Prometheus alert rules, see Create an alert rule for a Prometheus instance.