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

pl.allegro.tech.hermes.common.metric.ConsumerMetrics 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 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))
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy