@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"); 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.SUMMARY, "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> labelNamesWithQuantile = new ArrayList<String>(labelNames); labelNamesWithQuantile.add("quantile"); for(Map.Entry<Double, Double> q : v.quantiles.entrySet()) { List<String> labelValuesWithQuantile = new ArrayList<String>(c.getKey()); labelValuesWithQuantile.add(doubleToGoString(q.getKey())); samples.add(new MetricFamilySamples.Sample(fullname, labelNamesWithQuantile, labelValuesWithQuantile, q.getValue())); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.count)); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.SUMMARY, samples); }
Summary extends SimpleCollector<Summary.Child> implements Counter.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> labelNamesWithQuantile = new ArrayList<String>(labelNames); labelNamesWithQuantile.add("quantile"); for(Map.Entry<Double, Double> q : v.quantiles.entrySet()) { List<String> labelValuesWithQuantile = new ArrayList<String>(c.getKey()); labelValuesWithQuantile.add(doubleToGoString(q.getKey())); samples.add(new MetricFamilySamples.Sample(fullname, labelNamesWithQuantile, labelValuesWithQuantile, q.getValue())); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.count)); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.SUMMARY, samples); } }
Summary extends SimpleCollector<Summary.Child> implements Counter.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> labelNamesWithQuantile = new ArrayList<String>(labelNames); labelNamesWithQuantile.add("quantile"); for(Map.Entry<Double, Double> q : v.quantiles.entrySet()) { List<String> labelValuesWithQuantile = new ArrayList<String>(c.getKey()); labelValuesWithQuantile.add(doubleToGoString(q.getKey())); samples.add(new MetricFamilySamples.Sample(fullname, labelNamesWithQuantile, labelValuesWithQuantile, q.getValue())); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.count)); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.SUMMARY, samples); } Summary(Builder b); }
Summary extends SimpleCollector<Summary.Child> implements Counter.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> labelNamesWithQuantile = new ArrayList<String>(labelNames); labelNamesWithQuantile.add("quantile"); for(Map.Entry<Double, Double> q : v.quantiles.entrySet()) { List<String> labelValuesWithQuantile = new ArrayList<String>(c.getKey()); labelValuesWithQuantile.add(doubleToGoString(q.getKey())); samples.add(new MetricFamilySamples.Sample(fullname, labelNamesWithQuantile, labelValuesWithQuantile, q.getValue())); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.count)); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.SUMMARY, samples); } Summary(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); Child.Value get(); @Override List<MetricFamilySamples> collect(); @Override List<MetricFamilySamples> describe(); }
Summary extends SimpleCollector<Summary.Child> implements Counter.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> labelNamesWithQuantile = new ArrayList<String>(labelNames); labelNamesWithQuantile.add("quantile"); for(Map.Entry<Double, Double> q : v.quantiles.entrySet()) { List<String> labelValuesWithQuantile = new ArrayList<String>(c.getKey()); labelValuesWithQuantile.add(doubleToGoString(q.getKey())); samples.add(new MetricFamilySamples.Sample(fullname, labelNamesWithQuantile, labelValuesWithQuantile, q.getValue())); } samples.add(new MetricFamilySamples.Sample(fullname + "_count", labelNames, c.getKey(), v.count)); samples.add(new MetricFamilySamples.Sample(fullname + "_sum", labelNames, c.getKey(), v.sum)); } return familySamplesList(Type.SUMMARY, samples); } Summary(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); Child.Value get(); @Override List<MetricFamilySamples> collect(); @Override List<MetricFamilySamples> describe();  }