use of com.codahale.metrics.Snapshot in project lucene-solr by apache.
the class MetricUtils method convertHistogram.
/**
* Convert an instance of {@link Histogram}. NOTE: it's assumed that histogram contains non-time
* based values that don't require unit conversion.
* @param name metric name
* @param histogram an instance of {@link Histogram}
* @param propertyFilter limit what properties of a metric are returned
* @param simple use simplified representation for complex metrics - instead of a (name, map)
* only the selected (name "." key, value) pairs will be produced.
* @param consumer consumer that accepts produced objects
*/
static void convertHistogram(String name, Histogram histogram, PropertyFilter propertyFilter, boolean simple, BiConsumer<String, Object> consumer) {
Snapshot snapshot = histogram.getSnapshot();
if (simple) {
if (propertyFilter.accept(MEAN)) {
consumer.accept(name + "." + MEAN, snapshot.getMean());
}
} else {
Map<String, Object> response = new LinkedHashMap<>();
String prop = "count";
if (propertyFilter.accept(prop)) {
response.put(prop, histogram.getCount());
}
// non-time based values
addSnapshot(response, snapshot, propertyFilter, false);
if (!response.isEmpty()) {
consumer.accept(name, response);
}
}
}
use of com.codahale.metrics.Snapshot in project lucene-solr by apache.
the class MetricUtils method addMetrics.
/**
* Adds metrics from a Timer to a NamedList, using well-known back-compat names.
* @param lst The NamedList to add the metrics data to
* @param timer The Timer to extract the metrics from
*/
public static void addMetrics(NamedList<Object> lst, Timer timer) {
Snapshot snapshot = timer.getSnapshot();
lst.add("avgRequestsPerSecond", timer.getMeanRate());
lst.add("5minRateRequestsPerSecond", timer.getFiveMinuteRate());
lst.add("15minRateRequestsPerSecond", timer.getFifteenMinuteRate());
lst.add("avgTimePerRequest", nsToMs(snapshot.getMean()));
lst.add("medianRequestTime", nsToMs(snapshot.getMedian()));
lst.add("75thPcRequestTime", nsToMs(snapshot.get75thPercentile()));
lst.add("95thPcRequestTime", nsToMs(snapshot.get95thPercentile()));
lst.add("99thPcRequestTime", nsToMs(snapshot.get99thPercentile()));
lst.add("999thPcRequestTime", nsToMs(snapshot.get999thPercentile()));
}
use of com.codahale.metrics.Snapshot in project lucene-solr by apache.
the class OverseerTest method printTimingStats.
private void printTimingStats(Timer timer) {
Snapshot snapshot = timer.getSnapshot();
log.info("\t avgRequestsPerSecond: {}", timer.getMeanRate());
log.info("\t 5minRateRequestsPerSecond: {}", timer.getFiveMinuteRate());
log.info("\t 15minRateRequestsPerSecond: {}", timer.getFifteenMinuteRate());
log.info("\t avgTimePerRequest: {}", nsToMs(snapshot.getMean()));
log.info("\t medianRequestTime: {}", nsToMs(snapshot.getMedian()));
log.info("\t 75thPcRequestTime: {}", nsToMs(snapshot.get75thPercentile()));
log.info("\t 95thPcRequestTime: {}", nsToMs(snapshot.get95thPercentile()));
log.info("\t 99thPcRequestTime: {}", nsToMs(snapshot.get99thPercentile()));
log.info("\t 999thPcRequestTime: {}", nsToMs(snapshot.get999thPercentile()));
}
use of com.codahale.metrics.Snapshot in project lucene-solr by apache.
the class MetricUtilsTest method testSolrTimerGetSnapshot.
@Test
public void testSolrTimerGetSnapshot() {
// create a timer with up to 100 data points
final Timer timer = new Timer();
final int iterations = random().nextInt(100);
for (int i = 0; i < iterations; ++i) {
timer.update(Math.abs(random().nextInt()) + 1, TimeUnit.NANOSECONDS);
}
// obtain timer metrics
Map<String, Object> map = new HashMap<>();
MetricUtils.convertTimer("", timer, MetricUtils.PropertyFilter.ALL, false, false, (k, v) -> {
map.putAll((Map<String, Object>) v);
});
NamedList lst = new NamedList(map);
// check that expected metrics were obtained
assertEquals(14, lst.size());
final Snapshot snapshot = timer.getSnapshot();
// cannot test avgRequestsPerMinute directly because mean rate changes as time increases!
// assertEquals(lst.get("avgRequestsPerSecond"), timer.getMeanRate());
assertEquals(timer.getFiveMinuteRate(), lst.get("5minRate"));
assertEquals(timer.getFifteenMinuteRate(), lst.get("15minRate"));
assertEquals(MetricUtils.nsToMs(snapshot.getMean()), lst.get("mean_ms"));
assertEquals(MetricUtils.nsToMs(snapshot.getMedian()), lst.get("median_ms"));
assertEquals(MetricUtils.nsToMs(snapshot.get75thPercentile()), lst.get("p75_ms"));
assertEquals(MetricUtils.nsToMs(snapshot.get95thPercentile()), lst.get("p95_ms"));
assertEquals(MetricUtils.nsToMs(snapshot.get99thPercentile()), lst.get("p99_ms"));
assertEquals(MetricUtils.nsToMs(snapshot.get999thPercentile()), lst.get("p999_ms"));
}
use of com.codahale.metrics.Snapshot in project sling by apache.
the class MetricWebConsolePlugin method addTimerDetails.
private void addTimerDetails(PrintWriter pw, SortedMap<String, Timer> timers) {
if (timers.isEmpty()) {
return;
}
pw.println("<br>");
pw.println("<div class='table'>");
pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Timers</div>");
pw.println("<table class='nicetable' id='data-timers'>");
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'>Mean Rate</th>");
pw.println("<th class='header'>1 min rate</th>");
pw.println("<th class='header'>5 mins rate</th>");
pw.println("<th class='header'>15 mins rate</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>Rate Unit</th>");
pw.println("<th>Duration Unit</th>");
pw.println("</tr>");
pw.println("</thead>");
pw.println("<tbody>");
String rowClass = "odd";
for (Map.Entry<String, Timer> e : timers.entrySet()) {
Timer t = e.getValue();
Snapshot s = t.getSnapshot();
String name = e.getKey();
double rateFactor = timeUnit.rateFor(name).toSeconds(1);
String rateUnit = "events/" + calculateRateUnit(timeUnit.rateFor(name));
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>", t.getCount());
pw.printf("<td>%f</td>", t.getMeanRate() * rateFactor);
pw.printf("<td>%f</td>", t.getOneMinuteRate() * rateFactor);
pw.printf("<td>%f</td>", t.getFiveMinuteRate() * rateFactor);
pw.printf("<td>%f</td>", t.getFifteenMinuteRate() * rateFactor);
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>", rateUnit);
pw.printf("<td>%s</td>", durationUnit);
pw.println("</tr>");
rowClass = "odd".equals(rowClass) ? "even" : "odd";
}
pw.println("</tbody>");
pw.println("</table>");
pw.println("</div>");
}
Aggregations