All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.hermes.common.metric.MaxRateMetrics Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
package pl.allegro.tech.hermes.common.metric;

import io.micrometer.core.instrument.MeterRegistry;
import pl.allegro.tech.hermes.api.SubscriptionName;
import pl.allegro.tech.hermes.metrics.HermesCounter;
import pl.allegro.tech.hermes.metrics.counters.HermesCounters;

import java.util.List;
import java.util.function.ToDoubleFunction;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static pl.allegro.tech.hermes.common.metric.SubscriptionTagsFactory.subscriptionTags;

public class MaxRateMetrics {

    private final MeterRegistry meterRegistry;

    MaxRateMetrics(MeterRegistry meterRegistry) {
        this.meterRegistry = meterRegistry;
    }

    public  void registerCalculationDurationInMillisGauge(T obj, ToDoubleFunction f) {
        meterRegistry.more().timeGauge("max-rate.calculation.duration", List.of(), obj, MILLISECONDS, f);
    }

    public HermesCounter historyUpdateFailuresCounter(SubscriptionName subscription) {
        return HermesCounters.from(
                meterRegistry.counter("max-rate.history-update.failures", subscriptionTags(subscription))
        );
    }

    public HermesCounter fetchFailuresCounter(SubscriptionName subscription) {
        return HermesCounters.from(
                meterRegistry.counter("max-rate.fetch.failures", subscriptionTags(subscription))
        );
    }

    public  void registerCalculatedRateGauge(SubscriptionName subscription, T obj, ToDoubleFunction f) {
        meterRegistry.gauge("max-rate.calculated-rate", subscriptionTags(subscription), obj, f);
    }

    public  void registerActualRateGauge(SubscriptionName subscription, T obj, ToDoubleFunction f) {
        meterRegistry.gauge("max-rate.actual-rate", subscriptionTags(subscription), obj, f);
    }

    public  void registerOutputRateGauge(SubscriptionName subscription, T obj, ToDoubleFunction f) {
        meterRegistry.gauge("max-rate.output-rate", subscriptionTags(subscription), obj, f);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy