use of com.codahale.metrics.Histogram in project ddf by codice.
the class SourceMetricsImpl method updateMetric.
public void updateMetric(String sourceId, String name, int incrementAmount) {
LOGGER.debug("sourceId = {}, name = {}", sourceId, name);
if (StringUtils.isBlank(sourceId) || StringUtils.isBlank(name)) {
return;
}
String mapKey = sourceId + "." + name;
SourceMetric sourceMetric = metrics.get(mapKey);
if (sourceMetric == null) {
LOGGER.debug("sourceMetric is null for {} - creating metric now", mapKey);
// Loop through list of all sources until find the sourceId whose metric is being
// updated
boolean created = createMetric(catalogProviders, sourceId);
if (!created) {
createMetric(federatedSources, sourceId);
}
sourceMetric = metrics.get(mapKey);
}
// If this metric already exists, then just update its MBean
if (sourceMetric != null) {
LOGGER.debug("CASE 1: Metric already exists for {}", mapKey);
if (sourceMetric.isHistogram()) {
Histogram metric = (Histogram) sourceMetric.getMetric();
LOGGER.debug("Updating histogram metric {} by amount of {}", name, incrementAmount);
metric.update(incrementAmount);
} else {
Meter metric = (Meter) sourceMetric.getMetric();
LOGGER.debug("Updating metric {} by amount of {}", name, incrementAmount);
metric.mark(incrementAmount);
}
return;
}
}
use of com.codahale.metrics.Histogram in project sling by apache.
the class MetricWebConsolePlugin method addHistogramDetails.
private void addHistogramDetails(PrintWriter pw, SortedMap<String, Histogram> histograms) {
if (histograms.isEmpty()) {
return;
}
pw.println("<br>");
pw.println("<div class='table'>");
pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Histograms</div>");
pw.println("<table class='nicetable' id='data-histograms'>");
pw.println("<thead>");
pw.println("<tr>");
pw.println("<th class='header'>Name</th>");
pw.println("<th class='header'>Count</th>");
pw.println("<th class='header'>50%</th>");
pw.println("<th class='header'>Min</th>");
pw.println("<th class='header'>Max</th>");
pw.println("<th class='header'>Mean</th>");
pw.println("<th class='header'>StdDev</th>");
pw.println("<th class='header'>75%</th>");
pw.println("<th class='header'>95%</th>");
pw.println("<th class='header'>98%</th>");
pw.println("<th class='header'>99%</th>");
pw.println("<th class='header'>999%</th>");
pw.println("<th>Duration Unit</th>");
pw.println("</tr>");
pw.println("</thead>");
pw.println("<tbody>");
String rowClass = "odd";
for (Map.Entry<String, Histogram> e : histograms.entrySet()) {
Histogram h = e.getValue();
Snapshot s = h.getSnapshot();
String name = e.getKey();
double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1);
String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US);
pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
pw.printf("<td>%s</td>", name);
pw.printf("<td>%d</td>", h.getCount());
pw.printf("<td>%f</td>", s.getMedian() * durationFactor);
pw.printf("<td>%f</td>", s.getMin() * durationFactor);
pw.printf("<td>%f</td>", s.getMax() * durationFactor);
pw.printf("<td>%f</td>", s.getMean() * durationFactor);
pw.printf("<td>%f</td>", s.getStdDev() * durationFactor);
pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor);
pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor);
pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor);
pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor);
pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor);
pw.printf("<td>%s</td>", durationUnit);
pw.println("</tr>");
rowClass = "odd".equals(rowClass) ? "even" : "odd";
}
pw.println("</tbody>");
pw.println("</table>");
pw.println("</div>");
}
use of com.codahale.metrics.Histogram in project sling by apache.
the class MetricWrapperTest method histogram.
@Test
public void histogram() throws Exception {
Histogram histo = registry.histogram("test");
HistogramImpl histoStats = new HistogramImpl(histo);
histoStats.update(100);
assertEquals(1, histo.getCount());
assertEquals(1, histoStats.getCount());
assertEquals(100, histo.getSnapshot().getMax());
assertSame(histo, histoStats.adaptTo(Histogram.class));
}
use of com.codahale.metrics.Histogram in project metrics by dropwizard.
the class MetricsModuleTest method serializesHistograms.
@Test
public void serializesHistograms() throws Exception {
final Histogram histogram = mock(Histogram.class);
when(histogram.getCount()).thenReturn(1L);
final Snapshot snapshot = mock(Snapshot.class);
when(snapshot.getMax()).thenReturn(2L);
when(snapshot.getMean()).thenReturn(3.0);
when(snapshot.getMin()).thenReturn(4L);
when(snapshot.getStdDev()).thenReturn(5.0);
when(snapshot.getMedian()).thenReturn(6.0);
when(snapshot.get75thPercentile()).thenReturn(7.0);
when(snapshot.get95thPercentile()).thenReturn(8.0);
when(snapshot.get98thPercentile()).thenReturn(9.0);
when(snapshot.get99thPercentile()).thenReturn(10.0);
when(snapshot.get999thPercentile()).thenReturn(11.0);
when(snapshot.getValues()).thenReturn(new long[] { 1, 2, 3 });
when(histogram.getSnapshot()).thenReturn(snapshot);
assertThat(mapper.writeValueAsString(histogram)).isEqualTo("{" + "\"count\":1," + "\"max\":2," + "\"mean\":3.0," + "\"min\":4," + "\"p50\":6.0," + "\"p75\":7.0," + "\"p95\":8.0," + "\"p98\":9.0," + "\"p99\":10.0," + "\"p999\":11.0," + "\"stddev\":5.0}");
final ObjectMapper fullMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, true, MetricFilter.ALL));
assertThat(fullMapper.writeValueAsString(histogram)).isEqualTo("{" + "\"count\":1," + "\"max\":2," + "\"mean\":3.0," + "\"min\":4," + "\"p50\":6.0," + "\"p75\":7.0," + "\"p95\":8.0," + "\"p98\":9.0," + "\"p99\":10.0," + "\"p999\":11.0," + "\"values\":[1,2,3]," + "\"stddev\":5.0}");
}
Aggregations