MetricRegistry { public Histogram histogram(String name, Double... pcts) { if (histograms.containsKey(name)) { return histograms.get(name); } else { Histogram histogram = new Histogram(((pcts != null) && (pcts.length > 0)) ? pcts : defaultPcts); return register(histograms, name, histogram); } }  void registerGauge(String name, Gauge gauge); Counter counter(String name); Histogram histogram(String name, Double... pcts); Timer timer(String name, Double... pcts); void clearAll(); Map<String, Gauge> getGauges(); Map<String, Counter> getCounters(); Map<String, Histogram> getHistograms(); Map<String, Timer> getTimers(); void setDefaultPcts(Double[] defaultPcts); void addListener(MetricRegistryListener listener); static String name(String name, String... subNames); static SortedMap<String, T> getSortedMetrics(Map<String, T> metrics); static final MetricRegistry INSTANCE; }
@Test public void histogram() { MetricRegistry metricRegistry = new MetricRegistry(); Histogram histogram = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.latency")); assertThat(histogram).isNotNull(); Map<String, Histogram> histograms = metricRegistry.getHistograms(); Histogram histogram2 = histograms.get("UserService.getUser.latency"); assertThat(histogram2).isNotNull().isSameAs(histogram); Histogram histogram3 = metricRegistry.histogram(MetricRegistry.name("UserService", "getUser.latency")); assertThat(histogram3).isNotNull().isSameAs(histogram); }