1

Нужно собрать метрику, для этих целей использую решение из коробки спринга Зависимости в помнике

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
        </dependency>

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

В сервисном слое есть код

@Autowired
MeterRegistry meterRegistry

this.meterRegistry.counter(order.getorderTypeId() + "_counter_" + statusRequest.getStatus());

Counter counter = this.meterRegistry.counter(order.getorderTypeId() + "_counter_" + order.getStatus());
counter.increment(-1.0);

Почему - то "counter.increment(-1.0)" не отнимает значение от текущего счетчика. А повышение ".increment()" счётчика отлично работает.

2
  • а метод .decrement() вам не поможет?
    – Komdosh
    20 окт 2020 в 7:54
  • @Komdosh У класса Counter нет метода .decrement() ((
    – Aleks
    20 окт 2020 в 8:20

1 ответ 1

0

Всем спасибо, но я нашел решение может это костыль, но он работает.

Counter counter = meterRegistry.counter(operation.getorderTypeId() + "_counter_" + order.getStatus());
        double count = counter.count();
        if (count > 0) {
            meterRegistry.remove(meterRegistry.counter(order.getorderTypeId() + "_counter_" + order.getStatus()));
            meterRegistry.counter(order.getorderTypeId() + "_counter_" + order.getStatus()).increment(count - 1);
        }

Я удаляю счетчик и создаю заново со значением меньше на 1.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.