All Products
Search
Document Center

Application Real-Time Monitoring Service:Use Managed Service for Prometheus to monitor Micrometer Java applications

Last Updated:Aug 03, 2023

This topic describes how to use Managed Service for Prometheus to monitor Micrometer Java applications.

Prerequisites

  • A Java application is created.

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

Step 1: Add Spring Boot Actuator dependencies to the Java application

  1. Add Spring Boot Actuator dependencies to the pom.xml file of the Maven project.

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <version>x.y.x<version>
    </dependency>
    Note

    For 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 ports and range of Managed Service for Prometheus monitoring data.

    management.server.port=8080
    management.endpoints.web.exposure.include=xxx, prometheus

Step 2: Add Micrometer dependencies to the Java application

Add Micrometer dependencies 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

For the latest Maven project version, visit the Alibaba Cloud repository.

Step 3: Add Micrometer JVM Extras dependencies to the Java application (recommended)

  1. Add Micrometer JVM Extras dependencies to the pom.xml file of the Maven project.

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

    For the latest Maven project version, visit the Alibaba Cloud repository.

  2. 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();
    }

Step 4: Deploy the Java application to an ECS instance or an ACK cluster

Deploy the Java application to an ECS instance or an ACK cluster based on your business requirements. Then, access the URL of the application that you want to listen on and check whether the metrics are exposed. Sample URL: http://localhost:8080/actuator/prometheus. Port 8080 is used as an example. Change the port number in the application.properties file.

Step 5: Configure a Micrometer exporter for the Prometheus instance

Procedure

Procedure 1: Integration center of the Prometheus instance

  1. Log on to the ARMS console.
  2. In the left-side navigation pane, choose Prometheus Service > Prometheus Instances.
  3. Click the name of the Prometheus instance instance that you want to manage to go to the Integration Center page.

Procedure 2: Integration Center in the left-side navigation pane of the ARMS console

  1. Log on to the Application Real-Time Monitoring Service (ARMS) console.

  2. In the left-side navigation pane, click Integration Center. In the Application Components section, find the Micrometer component and click Add. In the panel that appears, configure a Micrometer exporter as prompted.

Configure a Micrometer exporter

This section describes how to configure a Micrometer exporter in the integration center of the Prometheus instance. Perform the following steps:

  1. Configure a Micrometer exporter.

    • If you install the Micrometer component for the first time, perform the following operation

      In the Not Installed section of the Integration Center page, find the MicroMeter component and click Install.

      Note

      You can click the component to view the common Micrometer metrics and dashboard thumbnails in the panel that appears. The metrics listed are for reference only. After you install the Micrometer component in Managed Service for Prometheus, you can view the actual metrics.

    • If you have installed the MicroMeter component, you must add the component again.

      In the Installed section of the Integration Center page, find the MicroMeter component and click Add.

  2. On the Configuration tab in the STEP2 section of the panel that appears, set the parameters and click OK.

    Parameter

    Description

    exporter name

    The name of the exporter. Example: my-micrometer-1.

    • The name can contain only lowercase letters, digits, and hyphens (-) and cannot start or end with a hyphen (-).

    • The name must be unique.

    Pod/ECS Label Key (service discovery)

    Configure a tag key for the ECS instance or the pod of the ACK cluster to collect metrics from the ECS instance or the pod.

    Pod/ECS Label value

    Configure a tag value for the ECS instance or the pod of the ACK cluster to collect metrics from the ECS instance or the pod.

    MicroMeter listening port

    The listening port specified in the application.properties file of the Spring Boot application.

    Metrics path

    The HTTP path of the metrics exposed by Micrometer. Default value: /actuator/prometheus.

    Metrics scrape interval (seconds)

    The interval at which Managed Service for Prometheus collects the monitoring data. Default value: 30.

    Note

    You can view the monitoring metrics on the Metrics tab in the STEP2 section.

    You can also click the Micrometer component in the Installed section of the Integration Center page. In the panel that appears, you can view information such as targets, metrics, dashboards, service discovery configurations, and exporters. For more information, see Integration center.

Step 6: View the Grafana dashboard

On the Integration Center page, click the MicroMeter component in the Installed section. In the panel that appears, click the Dashboards tab to view the thumbnails and hyperlinks of Micrometer dashboards. Click a hyperlink to go to the Grafana page and view the dashboard.

Step 7: Configure alert rules for the Micrometer component

On the Integration Center page, click the MicroMeter component in the Installed section. In the panel that appears, click the Alert tab to view the alert rules of Managed Service for Prometheus.

When you install the Micrometer component in the integration center, the system adds common JVM alert rules by default. You only need to manually modify the threshold values and enable the alert rules. You can also create alert rules based on your business requirements. For more information, see Create an alert rule for a Prometheus instance.