Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot 2 actuator metrics

Is there any reference detailed documentation of spring boot 2 metrics.

I mean

{
  "names": [
    "jvm.memory.max",
    "http.server.requests",
    "process.files.max",
    "jvm.gc.memory.promoted",
    "tomcat.cache.hit",
    "rabbitmq.channels",
    "system.load.average.1m",
    "tomcat.cache.access",
    "jvm.memory.used",
    "jvm.gc.max.data.size",
    "jdbc.connections.max",
    "jdbc.connections.min",
    "jvm.gc.pause",
    "jvm.memory.committed",
    "system.cpu.count",
    "logback.events",
    "rabbitmq.connections",
    "tomcat.global.sent",
    "jvm.buffer.memory.used",
    "tomcat.sessions.created",
    "jvm.threads.daemon",
    "system.cpu.usage",
    "jvm.gc.memory.allocated",
    "tomcat.global.request.max",
    "hikaricp.connections.idle",
    "hikaricp.connections.pending",
    "tomcat.global.request",
    "rabbitmq.rejected",
    "tomcat.sessions.expired",
    "hikaricp.connections",
    "jvm.threads.live",
    "jvm.threads.peak",
    "tomcat.global.received",
    "hikaricp.connections.active",
    "hikaricp.connections.creation",
    "process.uptime",
    "tomcat.sessions.rejected",
    "process.cpu.usage",
    "tomcat.threads.config.max",
    "jvm.classes.loaded",
    "hikaricp.connections.max",
    "hikaricp.connections.min",
    "rabbitmq.consumed",
    "jvm.classes.unloaded",
    "tomcat.global.error",
    "tomcat.sessions.active.current",
    "tomcat.sessions.alive.max",
    "jvm.gc.live.data.size",
    "tomcat.servlet.request.max",
    "hikaricp.connections.usage",
    "tomcat.threads.current",
    "tomcat.servlet.request",
    "hikaricp.connections.timeout",
    "process.files.open",
    "jvm.buffer.count",
    "jvm.buffer.total.capacity",
    "tomcat.sessions.active.max",
    "hikaricp.connections.acquire",
    "tomcat.threads.busy",
    "rabbitmq.published",
    "process.start.time",
    "tomcat.servlet.error",
    "rabbitmq.acknowledged"
  ]
}
  • Which metrics should I use for memory / gc / cpu usage. Also what does the values represent.

  • Also in spring boot 1.5.x, i can simply get used heap, committed heap, gc count etc. How can i get those values?

Also is there a way I can get all metrics at one call. I mean to get all metrics i need to call many hits rite now in boot 2.

like image 554
Ankit Bansal Avatar asked Jun 20 '18 17:06

Ankit Bansal


People also ask

What is actuator in Spring Boot?

4. Spring Boot 1.x Actuator In 1.x, Actuator follows a read/write model, which means we can either read from it or write to it. For example, we can retrieve metrics or the health of our application. Alternatively, we could gracefully terminate our app or change our logging configuration.

What are the metrics in Spring Boot 2?

Spring Boot 2 autoconfigures quite a few metrics for you, including: Uptime: report a gauge for uptime and a fixed gauge representing the application’s absolute start time Many of these metrics existed in a form in Spring Boot 1, but have been enriched with greater detail and tags in Spring Boot 2. Which monitoring systems does Micrometer support?

What is Spring Boot micrometer?

Think of it like SLF4J, but for metrics! Micrometer is the metrics collection facility included in Spring Boot 2’s Actuator. It has also been backported to Spring Boot 1.5, 1.4, and 1.3 with the addition of another dependency. Micrometer adds richer meter primitives to the counters and gauges that existed in Spring Boot 1.

How to enable Spring Boot actuator in Maven?

To enable Spring Boot Actuator, we just need to add the spring-boot-actuator dependency to our package manager. In Maven: <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-actuator </artifactId> </dependency>. Note that this remains valid regardless of the Boot version, ...


1 Answers

Still learning how to use Spring's new dimensional implementation myself, but I think I can help you out with some of your question. As you found, the metrics are much richer in Spring Boot 2 than Spring Boot 1.5.

There's a good blog post on Spring's site that goes into detail what the new metric engine gives you and why they though the change was needed: Micrometer: Spring Boot 2's new application metrics collector

A. Which metrics should I use for memory / gc / cpu usage. Also what does the values represent.

When you navigate to your application's actuator/metric endpoint you can view your suitable metrics.

Memory

  • jvm.memory.max
  • jvm.memory.used
  • jvm.gc.memory.promoted
  • jvm.memory.committed
  • jvm.buffer.memory.used
  • jvm.gc.memory.allocated

GC

  • jvm.gc.memory.allocated
  • jvm.gc.memory.promoted

CPU

  • system.cpu.usage
  • system.cpu.count
  • process.cpu.usage

B. Also in spring boot 1.5.x, i can simply get used heap, committed heap, gc count etc. How can i get those values?

As you mentioned, you'll have to view your metrics by dimension.

For example, in Spring Boot <2, in order to view the heap.committed:120000, you'd have to just make a GET request on /actuator/metrics.

In Spring Boot 2, to return the metric for TOTAL committed memory (heap and nonheap) you'll make a GET request on /actuator/metrics/jvm.memory.committed.

You'll get a response similar to:

{
    "name": "jvm.memory.committed",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 240000
        }
    ],
    "availableTags": [
        {
            "tag": "area",
            "values": [
                "heap",
                "nonheap"
            ]
        },
        {
            "tag": "id",
            "values": [
                "Compressed Class Space",
                "PS Survivor Space",
                "PS Old Gen",
                "Metaspace",
                "PS Eden Space",
                "Code Cache"
            ]
        }
    ]
}

To only view the committed heap value, make a GET request using the heap tag: /acutator/metrics/jvm.memory.committted?tag=area:heap. You should see something similar to:

{
    "name": "jvm.memory.committed",
    "measurements": [
        {
            "statistic": "VALUE",
            "value": 120000
        }
    ],
    "availableTags": [
        {
            "tag": "id",
            "values": [
                "PS Eden Space",
                "PS Survivor Space",
                "PS Old Gen"
            ]
        }
    ]
}

Spring Boot's Metrics Reference Docs are a great resource and how I learned about the tag syntax (it's the last section).

See this question: Take a look at how previous versions mapped to the old metrics in Spring Boot's SystemPublicMetrics.java class if you'd like to ensure that these metrics are mapping correctly to your application's previous metrics.

Also is there a way I can get all metrics at one call. I mean to get all metrics i need to call many hits rite now in boot 2.

I don't think there is at this time through the metrics endpoint out of the box. Of interest to you may be Micrometer's HierarchicalNameMapper.java class. Per, Micrometer's Docs:

Dimensionality. Whether the system supports metric names to be enriched with tag key/value pairs. If a system is not dimensional, it is hierarchical, which means it only supports a flat metric name. When publishing metrics to hierarchical systems, Micrometer flattens the set of tag/key value pairs and adds them to the name.

So, if you publish your data to a hierarchical system (such as JMX) your metrics will be flattened. You could also implement your own flattening mapper if you're exporting to another system.

like image 160
Leo Avatar answered Oct 31 '22 18:10

Leo