Spring boot 2 actuator cache metrics
Asked Answered
B

1

6

I can't find cache metrics in sprint boot 2 actuator. How should I query for them or activate or debug?

org.springframework.boot:spring-boot-starter-actuator:2.2.5.RELEASE

I can see both caches under http://localhost:8080/actuator/caches ->

{
  "cacheManagers": {
    "cacheManager": {
      "caches": {
        "calendar": {
          "target": "org.ehcache.jsr107.Eh107Cache"
        },
        "foo": {
          "target": "org.ehcache.jsr107.Eh107Cache"
        }
      }
    }
  }
}

ehcache.xml:


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.ehcache.org/v3"
        xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
        xsi:schemaLocation="
            http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
            http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
    <cache alias="calendar" >
        <expiry>
            <ttl unit="seconds">60</ttl>
        </expiry>
        <resources>
            <heap unit="entries">2</heap>
            <offheap unit="MB">100</offheap>
        </resources>
    </cache>
    <cache alias="foo" >
        <expiry>
            <ttl unit="seconds">60</ttl>
        </expiry>
        <resources>
            <heap unit="entries">2</heap>
            <offheap unit="MB">100</offheap>
        </resources>
    </cache>
</config>

I can't see neither cache nor calendar nor foo under http://localhost:8080/actuator/metrics/ (other metrics like "jvm.memory.max" are visible)

similarly

http://localhost:8080/actuator/metrics/cache.calendar.size

http://localhost:8080/actuator/metrics/cache.calendar.gets

http://localhost:8080//actuator/metrics/cache.gets

doesn't return anything.

How can I get cache metrics?

http://localhost:8080/actuator/metrics/cache?tag=calendar:size also doesn't return anything, and in logs I can see:

2020-05-28 15:57:35.207 DEBUG 12490 --- [nio-8080-exec-3] org.apache.tomcat.util.http.Parameters   : Decoding query null UTF-8
2020-05-28 15:57:35.207 DEBUG 12490 --- [nio-8080-exec-3] org.apache.tomcat.util.http.Parameters   : Start processing with input [tag=calendar:size]
2020-05-28 15:57:35.207 DEBUG 12490 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : GET "/actuator/metrics/cache?tag=calendar:size", parameters={masked}
2020-05-28 15:57:35.207 DEBUG 12490 --- [nio-8080-exec-3] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped to Actuator web endpoint 'metrics-requiredMetricName'
2020-05-28 15:57:35.208 DEBUG 12490 --- [nio-8080-exec-3] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/vnd.spring-boot.actuator.v3+json;q=0.8', given [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8] and supported [application/vnd.spring-boot.actuator.v3+json, application/vnd.spring-boot.actuator.v2+json, application/json]
2020-05-28 15:57:35.209 DEBUG 12490 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2020-05-28 15:57:35.209 DEBUG 12490 --- [nio-8080-exec-3] o.s.s.w.a.ExceptionTranslationFilter     : Chain processed normally
Byzantine answered 28/5, 2020 at 12:47 Comment(3)
@DanielJacob it's not duplicate, /actuator/metrics/cache.gets doesn't return anything for me unlike in that postByzantine
You need to use tags to filter the metrics. Therefore it will be something like: localhost:8080//actuator/metrics/cache?tag=calendar:sizeHook
@DanielJacob localhost:8080/actuator/metrics/cache?tag=calendar:size doesn't return anything, I have updated my question and included logs concerning this queryByzantine
D
-1

In your cache configuration you could enable statistics:

<cache alias="calendar" >
    ...
    <jsr107:mbeans enable-statistics="true" />
</cache>
Deteriorate answered 30/9, 2020 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.