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

pl.allegro.tech.hermes.common.metric.TrackerElasticSearchMetrics 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.metrics.HermesTimer;

import java.util.function.ToDoubleFunction;

public class TrackerElasticSearchMetrics {
    private final MeterRegistry meterRegistry;
    private final GaugeRegistrar gaugeRegistrar;

    public TrackerElasticSearchMetrics(MeterRegistry meterRegistry) {
        this.meterRegistry = meterRegistry;
        this.gaugeRegistrar = new GaugeRegistrar(meterRegistry);
    }

    public  void registerProducerTrackerElasticSearchQueueSizeGauge(T stateObj, ToDoubleFunction f) {
        gaugeRegistrar.registerGauge(
                Gauges.TRACKER_ELASTICSEARCH_QUEUE_SIZE,
                stateObj, f
        );
    }

    public  void registerProducerTrackerElasticSearchRemainingCapacity(T stateObj, ToDoubleFunction f) {
        gaugeRegistrar.registerGauge(
                Gauges.TRACKER_ELASTICSEARCH_REMAINING_CAPACITY,
                stateObj, f
        );
    }

    public  void registerConsumerTrackerElasticSearchQueueSizeGauge(T stateObj, ToDoubleFunction f) {
        gaugeRegistrar.registerGauge(
                Gauges.TRACKER_ELASTICSEARCH_QUEUE_SIZE,
                stateObj, f
        );
    }

    public  void registerConsumerTrackerElasticSearchRemainingCapacity(T stateObj, ToDoubleFunction f) {
        gaugeRegistrar.registerGauge(
                Gauges.TRACKER_ELASTICSEARCH_REMAINING_CAPACITY,
                stateObj, f
        );
    }

    public HermesTimer trackerElasticSearchCommitLatencyTimer() {
        return HermesTimer.from(
                meterRegistry.timer(Timers.ELASTICSEARCH_COMMIT_LATENCY)
        );
    }

    private static class Gauges {
        public static final String TRACKER_ELASTICSEARCH_QUEUE_SIZE = "tracker.elasticsearch.queue-size";
        public static final String TRACKER_ELASTICSEARCH_REMAINING_CAPACITY = "tracker.elasticsearch.remaining-capacity";
    }

    private static class Timers {
        public static final String ELASTICSEARCH_COMMIT_LATENCY = "tracker.elasticsearch.commit-latency";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy