Micrometer - Prometheus Gauge displays NaN

后端 未结 4 1137
一个人的身影
一个人的身影 2021-02-20 12:59

I am trying to generate Prometheus metrics with using Micrometer.io with Spring Boot 2.0.0.RELEASE.

When I am trying to expose the size of a List as Gauge, it ke

4条回答
  •  余生分开走
    2021-02-20 14:00

    I had the same issue with Micrometer.io gauges when I used your method #1 meterRegistry.gauge("myGauge", new AtomicDouble()). I am using Scala by the way. I noticed that after I created about 50 gauges, the new gauges after that displayed NaN.

    Instead I used:

    val atomicDouble = new AtomicDouble()
    Gauge
      .builder("myGauge", atomicDouble, new AtomicDoubleToDoubleFunction)
      .strongReference(true)
      .register(meterRegistry)
    

    with

    class AtomicDoubleToDoubleFunction extends ToDoubleFunction[AtomicDouble] {
      override def applyAsDouble(value: AtomicDouble): Double = value.doubleValue()
    }
    

    This fixed the NaN issue, and all of my gauges appear correctly. I found the .strongReference(true) example from https://www.codota.com/code/java/classes/io.micrometer.core.instrument.Gauge .

提交回复
热议问题