All Products
Search
Document Center

Application Real-Time Monitoring Service:Monitor a Java application with Micrometer

Last Updated:Aug 27, 2026

This topic describes how to use Prometheus to monitor a Micrometer Java application.

Prerequisites

A Java application is created.

Step 1: Add MicroMeter to the Java application

Note

This topic uses the most commonly used Spring Boot 2.x application as an example.

  1. Add Spring Boot Actuator to the Java application -> Add the Actuator dependency to the pom.xml file of the project.

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

    To obtain the latest version, search in the Alibaba Cloud repository.

  2. Configure Actuator. Add the following configurations to the application.properties file to expose the port and scope of Prometheus 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 project.

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

    To obtain the latest version, search in the Alibaba Cloud repository.

  4. Add the MicroMeter JVM Extras dependency to the pom.xml file of the project.

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

    To obtain the latest version, search in the Alibaba Cloud repository.

  5. Configure MicroMeter JVM Extras. Add the following two Spring Bean definitions 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 Java application to Container Service or ECS.

    Deploy the Java business application to Container Service or ECS based on your business scenario. After the deployment succeeds, access the application listening address http://localhost:8080/actuator/prometheus (the 8080 port is the one that you specified in the application.properties configuration; modify the port in this URL based on the actual port value) to verify that the metrics are exposed correctly.

    After the access succeeds, the page returns Prometheus-format metric data similar to the following:

    # HELP jvm_memory_used_bytes The amount of used memory
    # TYPE jvm_memory_used_bytes gauge
    jvm_memory_used_bytes{area="heap",id="G1 Survivor Space",} 2964360.0
    jvm_memory_used_bytes{area="heap",id="G1 Old Gen",} 1.285324E7
    jvm_memory_used_bytes{area="nonheap",id="Metaspace",} 3.6128128E7
    jvm_memory_used_bytes{area="nonheap",id="CodeCache",} 9673088.0
    jvm_memory_used_bytes{area="heap",id="G1 Eden Space",} 6.7108864E7
    jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space",} 4999168.0
    # HELP jvm_threads_live_threads The current number of live threads including both daemon and non-daemon threads
    # TYPE jvm_threads_live_threads gauge
    jvm_threads_live_threads 28.0
    # HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the Java virtual machine to use
    # TYPE jvm_memory_committed_bytes gauge
    jvm_memory_committed_bytes{area="heap",id="G1 Survivor Space",} 4194304.0
    jvm_memory_committed_bytes{area="heap",id="G1 Old Gen",} 5.8720256E7
    jvm_memory_committed_bytes{area="nonheap",id="Metaspace",} 3.6569088E7
    jvm_memory_committed_bytes{area="nonheap",id="CodeCache",} 1.0682368E7
    jvm_memory_committed_bytes{area="heap",id="G1 Eden Space",} 9.646899E7
    jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space",} 5177344.0
    # HELP executor_pool_max_threads The maximum allowed number of threads in the pool
    # TYPE executor_pool_max_threads gauge
    executor_pool_max_threads{name="applicationTaskExecutor",} 2.147483647E9
    ...
    # TYPE jvm_buffer_count_buffers gauge
    jvm_buffer_count_buffers{id="mapped - 'non-volatile memory'",} 0.0
    jvm_buffer_count_buffers{id="mapped",} 0.0
    jvm_buffer_count_buffers{id="direct",} 7.0
    # HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool
    # TYPE jvm_buffer_total_capacity_bytes gauge
    jvm_buffer_total_capacity_bytes{id="mapped - 'non-volatile memory'",} 0.0
    jvm_buffer_total_capacity_bytes{id="mapped",} 0.0
    jvm_buffer_total_capacity_bytes{id="direct",} 57344.0
    # HELP jvm_threads_peak_threads The peak live thread count since the Java virtual machine started or peak was reset
    # TYPE jvm_threads_peak_threads gauge
    jvm_threads_peak_threads 30.0
    # HELP jvm_threads_states_threads The current number of threads
    # TYPE jvm_threads_states_threads gauge
    jvm_threads_states_threads{state="runnable",} 11.0
    jvm_threads_states_threads{state="blocked",} 0.0

Step 2: Integrate MicroMeter

  1. In the left-side navigation pane, choose Integration Center. Then, enter MicroMeter in the search box and click it.

  2. Log on to the Cloud Monitor console Cloud Monitor console .In the left-side navigation pane, choose Integration Center. Then, enter MicroMeter in the search box and click it.

    MicroMeter component in Integration Center

  3. On the Start Integration tab of the MicroMeter panel, select the Environment Type to complete the integration, and then click OK.

    Parameter

    Description

    Select the environment type

    You can integrate the following two service environments: Container Service environment, ECS (VPC).

    Select a cluster

    Select the target cluster.

    Pod labels

    The labels of the pod where the MicroMeter service is deployed. (We recommend that you use labels with specific identifiers.)

    Service port

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

    Metrics collection path

    The path through which MicroMeter metrics are exposed. The default path is automatically filled in.

    Use HTTPS for collection

    Metrics are collected over HTTP by default. If the service supports HTTPS and you want to collect metrics over HTTPS, turn on this switch.

    Metric collection interval (unit: seconds)

    The interval at which Managed Service for Prometheus collects metric data. Default value: 30 seconds.

Step 3: View MicroMeter dashboard data

  1. In the left-side navigation pane, click Provisioning. On the Integrated Environments tab of the Provisioning page, select the target environment. In the target environment list, click the name of the target environment to go to the container environment details page.

  2. Log on to the Cloud Monitor console Cloud Monitor console .In the left-side navigation pane, click Provisioning. On the Integrated Environments tab of the Provisioning page, select the target environment. In the target environment list, click the name of the target environment to go to the container environment details page.

    Integrated Environments tab on the Provisioning page

  3. On the Component Management tab, in the Addon Type section, click MicroMeter, and then click Dashboards to view all dashboard names.

    The dashboard list displays the JVM MicroMeter dashboard with the java, jvm, and micrometer tags.

  4. Click the name of the target dashboard to view the corresponding Grafana dashboard.

    The Grafana dashboard page displays the JVM MicroMeter monitoring dashboard. The top of the page provides the job and Instance drop-down filters and the Restart Detection switch. The Quick Facts section contains the Uptime and Start time metrics, and the I/O Overview section contains the Rate and Errors charts. Select the target instance to view the corresponding JVM monitoring data.

Step 4: Configure MicroMeter monitoring alerts

  1. On the Component Management tab, in the Addon Type section, click MicroMeter, and then click Alert Rules to view the alert rules that are created by default.

    The default alert rules include JVM CPU Usage Alert, JVM Memory Usage Alert, JVM Restart Count Alert, logback Log Error Count Alert, and MajorGC Duration Ratio Alert. All of them are at the P2 severity level and in the Running state.

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