Spring Actuator Metrics availableTags

Get useful metrics to monitor your app

With Spring Actuator API several useful metrics can be exposed that you can use to monitor your Spring Boot application. Metrics like application health or the last HTTP requests. I’ll show you how to do that.

I’ve made an example project you can found at https://github.com/claudioaltamura/docker-springboot-helloworld. After starting the app, you can curl the metrics with

curl -i -X GET http://localhost:8080/actuator/metrics

While consuming the API, you may notice the property „availableTags“, for example if you query the „jvm.memory.max“ metric:

curl -X GET 'http://localhost:8080/actuator/metrics/jvm.memory.max' | jq . 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   382    0   382    0     0  64169      0 --:--:-- --:--:-- --:--:-- 76400
{
  "name": "jvm.memory.max",
  "description": "The maximum amount of memory in bytes that can be used for memory management",
  "baseUnit": "bytes",
  "measurements": [
    {
      "statistic": "VALUE",
      "value": 5446303743
    }
  ],
  "availableTags": [
    {
      "tag": "area",
      "values": [
        "heap",
        "nonheap"
      ]
    },
    {
      "tag": "id",
      "values": [
        "Compressed Class Space",
        "PS Survivor Space",
        "PS Old Gen",
        "Metaspace",
        "PS Eden Space",
        "Code Cache"
      ]
    }
  ]
}

If you are interested in a specific metric, e.g. Comprossed Class Space than you can query only this metric like this:

curl -X GET 'http://localhost:8080/actuator/metrics/jvm.memory.max?tag=area%3Anonheap&tag=id%3ACompressed+Class+Space' | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   217    0   217    0     0  47132      0 --:--:-- --:--:-- --:--:-- 54250
{
  "name": "jvm.memory.max",
  "description": "The maximum amount of memory in bytes that can be used for memory management",
  "baseUnit": "bytes",
  "measurements": [
    {
      "statistic": "VALUE",
      "value": 1073741824
    }
  ],
  "availableTags": []
}

HTH 🙂

Links
Github Example https://github.com/claudioaltamura/docker-springboot-helloworld
Spring Boot Documentation https://docs.spring.io/spring-boot/docs/2.0.0.BUILD-SNAPSHOT/actuator-api//html/#metrics-drilling-down