jmx - Is there a way to enable Caffeine MBean registration?
问题描述
I am using Scaffeine in my project (https://github.com/blemale/scaffeine), a Scala wrapper for Caffeine (https://github.com/ben-manes/caffeine). I also have a prometheus JMX collector embedded in my metrics API (https://github.com/Segence/kamon-jmx-collector).
However when I launch my application, I can't really see any MBeans
for Caffeine in VisualVM.
Also, when looking at the Caffeine project, I found that in the caffeine/jcache/src/main/resources/reference.conf
there is a config for JMX monitoring:
monitoring {
# If cache statistics should be recorded and externalized
statistics = false
# If the configuration should be externalized
management = false
}
Both are set to false. Is there a way to configure Caffeine so that it exposes MBeans to JMX?
解决方案
谢谢本·马内斯,
根据普罗米修斯,这将是答案:
import io.prometheus.client.cache.caffeine.CacheMetricsCollector
CacheMetricsCollector cacheMetrics = new CacheMetricsCollector().register();
Cache<String, String> cache = Caffeine.newBuilder().recordStats().build();
cacheMetrics.addCache("myCacheLabel", cache);
推荐阅读
- dependencies - 如何使 docs/ 环境使用本地(尚未发布)的包版本
- java - 如果 URL 包含查询字符串参数,则屏幕截图在 selenium-chromedriver 中失败
- azure - Hive View 对 HDInsight 4.0 的本机支持
- reactjs - 如何为注册过程创建激活码?
- python - 从另一个数组的子集创建一个新数组
- linux - Netbeans 在 Linux 上构建 Ant 项目
- reactjs - 如何为钩子编写测试?
- .net - 使用 cyper 获取 neo4j 的内部唯一 ID 并将其分配给我的对象
- typescript - 配置 TSLint 以显示静态只读名称错误:'some_string'
- javascript - 检查时间戳是否超过 24 小时 - Javascript