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

io.prometheus.client.CounterMetricFamily Maven / Gradle / Ivy

There is a newer version: 0.16.0
Show newest version
package io.prometheus.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Counter metric family, for custom collectors and exporters.
 * 

* Most users want a normal {@link Counter} instead. * * Example usage: *

 * {@code
 *   class YourCustomCollector extends Collector {
 *     List collect() {
 *       List mfs = new ArrayList();
 *       // With no labels.
 *       mfs.add(new CounterMetricFamily("my_counter_total", "help", 42));
 *       // With labels
 *       CounterMetricFamily labeledCounter = new CounterMetricFamily("my_other_counter_total", "help", Arrays.asList("labelname"));
 *       labeledCounter.addMetric(Arrays.asList("foo"), 4);
 *       labeledCounter.addMetric(Arrays.asList("bar"), 5);
 *       mfs.add(labeledCounter);
 *       return mfs;
 *     }
 *   }
 * }
 * 
*/ public class CounterMetricFamily extends Collector.MetricFamilySamples { private final List labelNames; public CounterMetricFamily(String name, String help, double value) { super(name, Collector.Type.COUNTER, help, new ArrayList()); labelNames = Collections.emptyList(); samples.add( new Sample( name, labelNames, Collections.emptyList(), value)); } public CounterMetricFamily(String name, String help, List labelNames) { super(name, Collector.Type.COUNTER, help, new ArrayList()); this.labelNames = labelNames; } public CounterMetricFamily addMetric(List labelValues, double value) { if (labelValues.size() != labelNames.size()) { throw new IllegalArgumentException("Incorrect number of labels."); } samples.add(new Sample(name, labelNames, labelValues, value)); return this; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy