@Test public void testBuilderStyleUsage() { class YourCustomCollector extends Collector { public List<MetricFamilySamples> collect() { return Arrays.<MetricFamilySamples>asList( new GaugeMetricFamily("my_metric", "help", Arrays.asList("name")) .addMetric(Arrays.asList("value1"), 1.0) .addMetric(Arrays.asList("value2"), 2.0) ); } } new YourCustomCollector().register(registry); assertEquals(1.0, registry.getSampleValue("my_metric", new String[]{"name"}, new String[]{"value1"}) .doubleValue(), .001); assertEquals(2.0, registry.getSampleValue("my_metric", new String[]{"name"}, new String[]{"value2"}) .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);  }