【问题标题】:Metrics of redis and solr in spring bootspring boot中redis和solr的metrics
【发布时间】:2018-07-05 07:31:03
【问题描述】:

我在 Spring Boot 2.0.2 中内置了服务。我正在使用 redis 和 solrj。

现在,如果我想获取 redis 和 solr 的指标。它不会在

中显示
http://localhost:8080/actuator/metrics

有什么方法,例如制作自定义端点来获取 redis 和 solr 指标?

任何帮助将不胜感激..

【问题讨论】:

    标签: spring-boot redis spring-boot-actuator


    【解决方案1】:

    是的,应该可以的。

    Spring boot 2 的默认指标框架是Micrometer

    当这个框架被集成到 spring boot 应用程序中时(像往常一样通过 starter),任何报告给 micrometer 的指标都将立即出现在 spring boot 执行器中。

    所以问题是 redis/solrj 集成是否公开 Metrics。

    如果不是,您必须了解您想要测量的确切内容并插入集成。

    示例如下:

    import io.micrometer.core.annotation;
    
    @Timed("my-redis-calls")
    public void doSomethingInMyCode() {
        //call redis here 
    }
    

    当然也有程序化接口,使用注解不是强制的

    【讨论】:

      【解决方案2】:

      Mark Bramnik 的答案中显示的代码并未专门为您提供 Redis 客户端调用的时间,它为您提供 doSomethingInMyCode 方法的时间,这可能会有所不同。

      Lettuce 6.1 版本中似乎提供了千分尺支持。

      MeterRegistry meterRegistry = …;
      MicrometerOptions options = MicrometerOptions.create();
      ClientResources resources = ClientResources.builder().commandLatencyRecorder(new MicrometerCommandLatencyRecorder(meterRegistry, options)).build();
      
      RedisClient client = RedisClient.create(resources);
      

      https://lettuce.io/core/release/reference/index.html#command.latency.metrics.micrometer

      【讨论】:

        猜你喜欢
        • 2017-07-23
        • 2018-06-06
        • 1970-01-01
        • 2018-07-05
        • 2021-05-07
        • 2019-12-14
        • 2022-10-13
        • 2019-12-01
        • 2021-12-10
        相关资源
        最近更新 更多