@Test public void testJavadocExample() { class YourCustomCollector extends Collector { public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); mfs.add(new GaugeMetricFamily("my_gauge", "help", 42)); 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; } } new YourCustomCollector().register(registry); assertEquals(42.0, registry.getSampleValue("my_gauge").doubleValue(), .001); assertEquals(null, registry.getSampleValue("my_other_gauge")); assertEquals(4.0, registry.getSampleValue("my_other_gauge", new String[]{"labelname"}, new String[]{"foo"}).doubleValue(), .001); assertEquals(5.0, registry.getSampleValue("my_other_gauge", new String[]{"labelname"}, new String[]{"bar"}).doubleValue(), .001); }
public GaugeMetricFamily addMetric(List<String> 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; }
GaugeMetricFamily extends Collector.MetricFamilySamples { public GaugeMetricFamily addMetric(List<String> 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; } }
GaugeMetricFamily extends Collector.MetricFamilySamples { public GaugeMetricFamily addMetric(List<String> 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; } GaugeMetricFamily(String name, String help, double value);  GaugeMetricFamily(String name, String help, List<String> labelNames); }
GaugeMetricFamily extends Collector.MetricFamilySamples { public GaugeMetricFamily addMetric(List<String> 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; } GaugeMetricFamily(String name, String help, double value);  GaugeMetricFamily(String name, String help, List<String> labelNames); GaugeMetricFamily addMetric(List<String> labelValues, double value); }
GaugeMetricFamily extends Collector.MetricFamilySamples { public GaugeMetricFamily addMetric(List<String> 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; } GaugeMetricFamily(String name, String help, double value);  GaugeMetricFamily(String name, String help, List<String> labelNames); GaugeMetricFamily addMetric(List<String> labelValues, double value);  }