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

shade.polaris.io.prometheus.client.GaugeMetricFamily Maven / Gradle / Ivy

There is a newer version: 2.0.0.0-RC3
Show newest version
package io.prometheus.client;

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

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

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

 * {@code
 *   class YourCustomCollector extends Collector {
 *     List collect() {
 *       List mfs = new ArrayList();
 *       // With no labels.
 *       mfs.add(new GaugeMetricFamily("my_gauge", "help", 42));
 *       // With labels
 *       GaugeMetricFamily labeledGauge = new GaugeMetricFamily("my_other_gauge", "help", Arrays.asList("labelname"));
 *       labeledGauge.addMetric(Arrays.asList("foo"), 4);
 *       labeledGauge.addMetric(Arrays.asList("bar"), 5);
 *       mfs.add(labeledGauge);
 *       return mfs;
 *     }
 *   }
 * }
 * 
*/ public class GaugeMetricFamily extends Collector.MetricFamilySamples { private final List labelNames; public GaugeMetricFamily(String name, String help, double value) { super(name, Collector.Type.GAUGE, help, new ArrayList()); labelNames = Collections.emptyList(); samples.add( new Sample( name, labelNames, Collections.emptyList(), value)); } public GaugeMetricFamily(String name, String help, List labelNames) { super(name, Collector.Type.GAUGE, help, new ArrayList()); this.labelNames = labelNames; } public GaugeMetricFamily 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