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

com.aliyun.openservices.shade.io.prometheus.client.SummaryMetricFamily Maven / Gradle / Ivy

There is a newer version: 1.9.3.Final
Show newest version
package com.aliyun.openservices.shade.io.prometheus.client;

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

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

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

 * {@code
 *   class YourCustomCollector extends Collector {
 *     List collect() {
 *       List mfs = new ArrayList();
 *       // With no labels.
 *       mfs.add(new SummaryMetricFamily("my_summary", "help", 1, 42));
 *       // With labels. Record 95th percentile as 3, and 99th percentile as 5.
 *       SummaryMetricFamily labeledSummary = new SummaryMetricFamily("my_other_summary", "help", 
 *           Arrays.asList("labelname"), Arrays.asList(.95, .99));
 *       labeledSummary.addMetric(Arrays.asList("foo"), 2, 10, Arrays.asList(3.0, 5.0));
 *       mfs.add(labeledSummary);
 *       return mfs;
 *     }
 *   }
 * }
 * 
*/ public class SummaryMetricFamily extends Collector.MetricFamilySamples { private final List labelNames; private final List quantiles; public SummaryMetricFamily(String name, String help, double count, double sum) { super(name, Collector.Type.SUMMARY, help, new ArrayList()); this.labelNames = Collections.emptyList(); this.quantiles = Collections.emptyList(); addMetric(Collections.emptyList(), count, sum); } public SummaryMetricFamily(String name, String help, List labelNames) { this(name, help, labelNames, Collections.emptyList()); } public SummaryMetricFamily(String name, String help, List labelNames, Listquantiles) { super(name, Collector.Type.SUMMARY, help, new ArrayList()); this.labelNames = labelNames; this.quantiles = quantiles; } public SummaryMetricFamily addMetric(List labelValues, double count, double sum) { return addMetric(labelValues, count, sum, Collections.emptyList()); } public SummaryMetricFamily addMetric(List labelValues, double count, double sum, List quantiles) { if (labelValues.size() != labelNames.size()) { throw new IllegalArgumentException("Incorrect number of labels."); } if (this.quantiles.size() != quantiles.size()) { throw new IllegalArgumentException("Incorrect number of quantiles."); } samples.add(new Sample(name + "_count", labelNames, labelValues, count)); samples.add(new Sample(name + "_sum", labelNames, labelValues, sum)); List labelNamesWithQuantile = new ArrayList(labelNames); labelNamesWithQuantile.add("quantile"); for (int i = 0; i < quantiles.size(); i++) { List labelValuesWithQuantile = new ArrayList(labelValues); labelValuesWithQuantile.add(Collector.doubleToGoString(this.quantiles.get(i))); samples.add(new Sample(name, labelNamesWithQuantile, labelValuesWithQuantile, quantiles.get(i))); } return this; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy