pl.allegro.tech.hermes.common.metric.MaxRateMetrics Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-common Show documentation
Show all versions of hermes-common Show documentation
Fast and reliable message broker built on top of Kafka.
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);
}
}