pl.allegro.tech.hermes.common.metric.ConsumerMetrics 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 io.micrometer.core.instrument.Tags;
import pl.allegro.tech.hermes.api.Subscription;
import pl.allegro.tech.hermes.metrics.HermesCounter;
import pl.allegro.tech.hermes.metrics.HermesTimer;
import pl.allegro.tech.hermes.metrics.counters.HermesCounters;
import java.util.function.ToDoubleFunction;
import static pl.allegro.tech.hermes.common.metric.SubscriptionTagsFactory.subscriptionTags;
public class ConsumerMetrics {
private final MeterRegistry meterRegistry;
private final GaugeRegistrar gaugeRegistrar;
public ConsumerMetrics(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
this.gaugeRegistrar = new GaugeRegistrar(meterRegistry);
}
public void registerQueueUtilizationGauge(T obj, String queueName, ToDoubleFunction f) {
gaugeRegistrar.registerGauge("queue." + queueName + ".utilization", obj, f);
}
public HermesCounter queueFailuresCounter(String name) {
return HermesCounters.from(
meterRegistry.counter("queue." + name + ".failures")
);
}
public void registerConsumerProcessesThreadsGauge(T obj, ToDoubleFunction f) {
gaugeRegistrar.registerGauge("consumer-processes.threads", obj, f);
}
public void registerRunningConsumerProcessesGauge(T obj, ToDoubleFunction f) {
meterRegistry.gauge("consumer-processes.running", obj, f);
}
public void registerDyingConsumerProcessesGauge(T obj, ToDoubleFunction f) {
meterRegistry.gauge("consumer-processes.dying", obj, f);
}
public void registerBatchBufferTotalBytesGauge(T obj, ToDoubleFunction f) {
gaugeRegistrar.registerGauge("batch-buffer.total-bytes", obj, f);
}
public void registerBatchBufferAvailableBytesGauge(T obj, ToDoubleFunction f) {
gaugeRegistrar.registerGauge("batch-buffer.available-bytes", obj, f);
}
public HermesCounter oAuthSubscriptionTokenRequestCounter(Subscription subscription, String providerName) {
return HermesCounters.from(
meterRegistry.counter("oauth.token-requests", Tags.concat(
subscriptionTags(subscription.getQualifiedName()),
"provider", providerName
))
);
}
public HermesTimer oAuthProviderLatencyTimer(String providerName) {
return HermesTimer.from(
meterRegistry.timer("oauth.token-request-latency", Tags.of("provider", providerName))
);
}
public HermesCounter processedSignalsCounter(String name) {
return HermesCounters.from(
meterRegistry.counter("signals.processed", Tags.of("signal", name))
);
}
public HermesCounter droppedSignalsCounter(String name) {
return HermesCounters.from(
meterRegistry.counter("signals.dropped", Tags.of("signal", name))
);
}
}