You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Quarkus应用中启用Redis缓存的Micrometer指标?

Quarkus Redis缓存指标支持与启用方法

Quarkus完全支持Redis缓存的指标采集,官方缓存指南侧重内存缓存(Caffeine)的说明,但Redis缓存的指标可以通过搭配对应扩展快速启用,步骤如下:

  • 添加必备扩展
    首先需要安装Redis缓存核心扩展和指标采集扩展,使用Quarkus CLI执行:

    quarkus extension add redis-cache micrometer
    

    也可以在Maven/Gradle的依赖管理中手动添加这两个扩展的坐标。

  • 配置Redis连接与缓存
    在application.properties中配置Redis服务地址,以及缓存的基本规则(比如过期时间):

    # Redis连接地址
    quarkus.redis.hosts=redis://localhost:6379
    # 示例:配置名为my-cache的Redis缓存,写入后5分钟过期
    quarkus.cache.redis.my-cache.expire-after-write=5m
    
  • 自动启用指标采集
    只要添加了micrometer扩展,Redis缓存的指标会自动被采集,涵盖缓存命中、未命中、写入、删除等核心维度。这些指标以cache.*为前缀,比如cache.gets.hits、cache.gets.misses,指标标签中会明确标注缓存类型为redis以及对应的缓存名称。

  • 验证指标
    启动应用后,访问Quarkus的指标端点/q/metrics,就能看到所有采集到的Redis缓存指标。可以用curl快速验证:

    curl http://localhost:8080/q/metrics | grep cache
    
  • 可选:自定义指标过滤
    如果需要只暴露缓存相关指标,可以在application.properties中配置:

    quarkus.micrometer.export.prometheus.include=cache.*
    

内容的提问来源于stack exchange,提问作者GeauxEric

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 20:22:12