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