@Test public void testCollect() { labels.labels("a").observe(2); List<Collector.MetricFamilySamples> mfs = labels.collect(); ArrayList<Collector.MetricFamilySamples.Sample> samples = new ArrayList<Collector.MetricFamilySamples.Sample>(); ArrayList<String> labelNames = new ArrayList<String>(); labelNames.add("l"); ArrayList<String> labelValues = new ArrayList<String>(); labelValues.add("a"); ArrayList<String> labelNamesLe = new ArrayList<String>(labelNames); labelNamesLe.add("le"); for (String bucket: new String[]{"0.005", "0.01", "0.025", "0.05", "0.075", "0.1", "0.25", "0.5", "0.75", "1.0"}) { ArrayList<String> labelValuesLe = new ArrayList<String>(labelValues); labelValuesLe.add(bucket); samples.add(new Collector.MetricFamilySamples.Sample("labels_bucket", labelNamesLe, labelValuesLe, 0.0)); } for (String bucket: new String[]{"2.5", "5.0", "7.5", "10.0", "+Inf"}) { ArrayList<String> labelValuesLe = new ArrayList<String>(labelValues); labelValuesLe.add(bucket); samples.add(new Collector.MetricFamilySamples.Sample("labels_bucket", labelNamesLe, labelValuesLe, 1.0)); } samples.add(new Collector.MetricFamilySamples.Sample("labels_count", labelNames, labelValues, 1.0)); samples.add(new Collector.MetricFamilySamples.Sample("labels_sum", labelNames, labelValues, 2.0)); Collector.MetricFamilySamples mfsFixture = new Collector.MetricFamilySamples("labels", Collector.Type.HISTOGRAM, "help", samples); assertEquals(1, mfs.size()); assertEquals(mfsFixture, mfs.get(0)); }
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(); for(Map.Entry<List<String>, Child> c: children.entrySet()) { Child.Value v = c.getValue().get(); List<String> labelNamesWithLe = new ArrayList<String>(labelNames); labelNamesWithLe.add("le"); for (int i = 0; i < v.buckets.length; ++i) { List<String> labelValuesWithLe = new ArrayList<String>(c.getKey()); labelValuesWithLe.add(doubleToGoString(buckets[i])); samples.add(new MetricFamilySamples.Sample(fullname + "_bucket", labelNamesWithLe, labelValuesWithLe, v.buckets[i])); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.buckets[buckets.length-1])); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.HISTOGRAM, samples); }
Histogram extends SimpleCollector<Histogram.Child> implements Collector.Describable { @Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(); for(Map.Entry<List<String>, Child> c: children.entrySet()) { Child.Value v = c.getValue().get(); List<String> labelNamesWithLe = new ArrayList<String>(labelNames); labelNamesWithLe.add("le"); for (int i = 0; i < v.buckets.length; ++i) { List<String> labelValuesWithLe = new ArrayList<String>(c.getKey()); labelValuesWithLe.add(doubleToGoString(buckets[i])); samples.add(new MetricFamilySamples.Sample(fullname + "_bucket", labelNamesWithLe, labelValuesWithLe, v.buckets[i])); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.buckets[buckets.length-1])); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.HISTOGRAM, samples); } }
Histogram extends SimpleCollector<Histogram.Child> implements Collector.Describable { @Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(); for(Map.Entry<List<String>, Child> c: children.entrySet()) { Child.Value v = c.getValue().get(); List<String> labelNamesWithLe = new ArrayList<String>(labelNames); labelNamesWithLe.add("le"); for (int i = 0; i < v.buckets.length; ++i) { List<String> labelValuesWithLe = new ArrayList<String>(c.getKey()); labelValuesWithLe.add(doubleToGoString(buckets[i])); samples.add(new MetricFamilySamples.Sample(fullname + "_bucket", labelNamesWithLe, labelValuesWithLe, v.buckets[i])); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.buckets[buckets.length-1])); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.HISTOGRAM, samples); } Histogram(Builder b); }
Histogram extends SimpleCollector<Histogram.Child> implements Collector.Describable { @Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(); for(Map.Entry<List<String>, Child> c: children.entrySet()) { Child.Value v = c.getValue().get(); List<String> labelNamesWithLe = new ArrayList<String>(labelNames); labelNamesWithLe.add("le"); for (int i = 0; i < v.buckets.length; ++i) { List<String> labelValuesWithLe = new ArrayList<String>(c.getKey()); labelValuesWithLe.add(doubleToGoString(buckets[i])); samples.add(new MetricFamilySamples.Sample(fullname + "_bucket", labelNamesWithLe, labelValuesWithLe, v.buckets[i])); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.buckets[buckets.length-1])); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.HISTOGRAM, samples); } Histogram(Builder b); static Builder build(String name, String help); static Builder build(); void observe(double amt); Timer startTimer(); double time(Runnable timeable); E time(Callable<E> timeable); @Override List<MetricFamilySamples> collect(); @Override List<MetricFamilySamples> describe(); }
Histogram extends SimpleCollector<Histogram.Child> implements Collector.Describable { @Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(); for(Map.Entry<List<String>, Child> c: children.entrySet()) { Child.Value v = c.getValue().get(); List<String> labelNamesWithLe = new ArrayList<String>(labelNames); labelNamesWithLe.add("le"); for (int i = 0; i < v.buckets.length; ++i) { List<String> labelValuesWithLe = new ArrayList<String>(c.getKey()); labelValuesWithLe.add(doubleToGoString(buckets[i])); samples.add(new MetricFamilySamples.Sample(fullname + "_bucket", labelNamesWithLe, labelValuesWithLe, v.buckets[i])); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.buckets[buckets.length-1])); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.HISTOGRAM, samples); } Histogram(Builder b); static Builder build(String name, String help); static Builder build(); void observe(double amt); Timer startTimer(); double time(Runnable timeable); E time(Callable<E> timeable); @Override List<MetricFamilySamples> collect(); @Override List<MetricFamilySamples> describe();  }