private UntypedMetric get(Identifier dim, UntypedMetric other) { UntypedMetric v = values.get(dim); if (v == null) { v = new UntypedMetric(other.getMetricDefinition()); values.put(dim, v); } return v; }
static MetricValue convert(UntypedMetric val) { if (val.isCounter()) { return CountMetric.newInstance(val.getCount()); } else { if (val.getHistogram() == null) { return GaugeMetric.newInstance(val.getLast(), val.getMax(), val.getMin(), val.getSum(), val.getCount()); } else { return GaugeMetric.newInstance(val.getLast(), val.getMax(), val.getMin(), val.getSum(), val.getCount(), Optional.of(buildPercentileList(val.getHistogram()))); } } }
void put(Sample x) { UntypedMetric value = get(x); Measurement m = x.getMeasurement(); switch (x.getMetricType()) { case GAUGE: value.put(m.getMagnitude()); break; case COUNTER: value.add(m.getMagnitude()); break; default: throw new IllegalArgumentException("Unsupported metric type: " + x.getMetricType()); } }
UntypedMetric pruneData() { UntypedMetric pruned = new UntypedMetric(null); pruned.outputFormat = this.outputFormat; pruned.current = this.current; return pruned; }
void outputHistograms(PrintStream output) { boolean gotHistogram = false; for (Map.Entry<Identifier, UntypedMetric> entry : snapshot.entrySet()) { if (entry.getValue().getHistogram() == null) { continue; } gotHistogram = true; DoubleHistogram histogram = entry.getValue().getHistogram(); Identifier id = entry.getKey(); String metricIdentifier = getIdentifierString(id); output.println("# start of metric " + metricIdentifier); histogram.outputPercentileDistribution(output, 4, 1.0d, true); output.println("# end of metric " + metricIdentifier); } if (!gotHistogram) { output.println("# No histograms currently available."); } }
private UntypedMetric get(Sample sample) { Identifier dim = sample.getIdentifier(); UntypedMetric v = values.get(dim); if (v == null) { // please keep inside guard, as sample.getHistogramDefinition(String) touches a volatile v = new UntypedMetric(sample.getHistogramDefinition(dim.getName())); values.put(dim, v); } return v; }