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

com.sproutsocial.metrics.gauges.MeteredRatioGauge Maven / Gradle / Ivy

package com.sproutsocial.metrics.gauges;

import java.util.function.Function;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metered;
import com.codahale.metrics.RatioGauge;

/**
 * Created on 4/19/15
 *
 * A {@link Gauge} that reports the
 * ratio of two {@link Metered} objects
 *
 * @author horthy
 */
public class MeteredRatioGauge extends RatioGauge {
    
    private final Metered numerator;
    private final Metered denominator;
    private final Function accessor;

    public MeteredRatioGauge(Metered numerator, Metered denominator, Function accessor) {
        this.numerator = numerator;
        this.denominator = denominator;
        this.accessor = accessor;
    }
    
    public MeteredRatioGauge(Metered numerator, Metered denominator) {
        this(numerator, denominator, Metered::getOneMinuteRate);
    }

    @Override
    protected Ratio getRatio() {
        return Ratio.of(
                accessor.apply(numerator),
                accessor.apply(denominator));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy