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

com.librato.metrics.CounterMeasurement Maven / Gradle / Ivy

package com.librato.metrics;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static com.librato.metrics.Preconditions.checkNotNull;

/**
 * Represents a reading from a counter
 */
public class CounterMeasurement implements Measurement {
    private static final Map emptyAttributes = Collections.emptyMap();
    private final Number period;
    private final String source;
    private final String name;
    private final Long count;
    private final Map metricAttributes;

    public static CounterMeasurementBuilder builder(String name, Long count) {
        return new CounterMeasurementBuilder(name, count);
    }

    public CounterMeasurement(String name, Long count) {
        this(null, null, name, count);
    }

    public CounterMeasurement(String source, String name, Long count) {
        this(source, null, name, count);
    }

    public CounterMeasurement(String source, Number period, String name, Long count) {
        this(source, period, name, count, emptyAttributes);
    }

    public CounterMeasurement(String source, Number period, String name, Long count, Map metricAttributes) {
        this.source = source;
        this.period = period;
        this.name = checkNotNull(name);
        this.count = checkNotNull(count);
        this.metricAttributes = metricAttributes;
    }

    public Map getMetricAttributes() {
        return metricAttributes;
    }

    public String getSource() {
        return source;
    }

    public Number getPeriod() {
        return period;
    }

    public String getName() {
        return name;
    }

    public Map toMap() {
        final Map value = new HashMap(1);
        value.put("value", count);
        return value;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy