I have a SpringBoot 2.2.4.RELEASE
with a RestRepostory like
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
@RestController
public class MyController {
private MeterRegistry meterRegistry;
public MyController(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}
private Gauge myGauge;
private Integer myInteger = 0;
@PostConstruct
private void init() {
myGauge = Gauge.builder("my.gauge", myInteger, Integer::intValue)
.register(meterRegistry);
}
@GetMapping("/count")
public void count() {
myInteger = 5;
}
}
After the application is started, going to http://localhost:8082/actuator/prometheus I can see
# HELP my_gauge
# TYPE my_gauge gauge
my_gauge 0.0
But after going to http://localhost:8082/count/, the value remains 0.0
What's the problem ? I also don't understand the 3rd parameter of the builder function. Is the the cause ?
I also tried with a Counter. And it's working fine when I increment it withing the count function.