Как программно использовать конечные точки привода?

#java #spring-boot #metrics #spring-boot-actuator

#java #весенняя загрузка #показатели #spring-boot-actuator

Вопрос:

Мне нужны некоторые показатели для приложения spring boot. Поэтому я использовал MetricsEndpoint, как показано ниже. Но я не могу получить доступ к метрикам. метод invoke() не отображается.

версия spring boot: 2.2.6.RELEASE

 @Controller
public class DashboardControllerImpl implements IDashboardController {

    @Autowired
    private MetricsEndpoint metricsEndpoint;

    @Override
    public ResponseEntity listDiskUsage() {
        metricsEndpoint.invoke(); // invoke does not appear

        // code block
    }
}
 

Ответ №1:

Я нашел что-то подобное, что решило мою проблему!

 ((MetricsEndpoint.Sample)metricsEndpoint.metric("process.uptime", null).getMeasurements().get(0)).getValue()