Search code examples
springspring-bootehcachenewrelic

Number of objects cached in production using EhCache


Is there any way to know the number of objects cached in production?

I am using EhCache on my project and NewRelic for monitoring.

I don't know if that help me too or if there is integration for NewRelic with EhCache.


Solution

  • You could potentially use NewRelic's JMX integration, but also there is JCache API integration in NewRelic, which may instrument the right parts if you are using the JCache compatible features of EhCache.

    If you want to export select JMX information, then you need to specify in your NewRelic config on the server as documented here.

    For example you could create the following file in /opt/newrelic/extension/ehcache.yaml

    name: EhCacheMetrics
    version: 1.0
    enabled: true
    jmx:
      - object_name: {see Metadata within VisualVM MBeans browser}
        metrics:
          - attributes: CacheHitPercentage, CacheHits, CacheMisses, ObjectCount
            type: simple
    

    You'll need to find out what is available which you can do by registering EhCache for JMX management as documented here.

    There is a good Spring Boot sample here