protected String getRateString(double value) { return toString(value * rateFactor); }
protected void writeMeter(Meter meter, BufferedWriter writer) throws IOException { writeMetered(meter, writer); }
protected void writeMetered(Metered metered, BufferedWriter writer) throws IOException { writeWithIndent("count = " + metered.getCount(), writer); writeWithIndent("mean rate = " + getRateString(metered.getMeanRate()), writer); writeWithIndent("1-minute rate = " + getRateString(metered.getOneMinuteRate()), writer); writeWithIndent("5-minute rate = " + getRateString(metered.getFiveMinuteRate()), writer); writeWithIndent("15-minute rate = " + getRateString(metered.getFifteenMinuteRate()), writer); writeWithIndent("rate unit = " + rateUnit, writer); }
log.debug("Found '{}' annotation on method '{}'", Metered.class.getSimpleName(), LangUtils.toString(method)); Metered metered = method.getAnnotation(Metered.class); String metricName = !metered.value().isEmpty() ? metered.value() : getMetricName(route, method); handler = new MeteredHandler(metricName, metricRegistry, route.getRouteHandler()); } else if (method.isAnnotationPresent(Timed.class)) { log.debug("Found '{}' annotation on method '{}'", Timed.class.getSimpleName(), LangUtils.toString(method)); Timed timed = method.getAnnotation(Timed.class); String metricName = !timed.value().isEmpty() ? timed.value() : getMetricName(route, method); handler = new TimedHandler(metricName, metricRegistry, route.getRouteHandler()); } else if (method.isAnnotationPresent(Counted.class)) { log.debug("Found '{}' annotation on method '{}'", Counted.class.getSimpleName(), LangUtils.toString(method)); Counted counted = method.getAnnotation(Counted.class); String metricName = !counted.value().isEmpty() ? counted.value() : getMetricName(route, method); handler = new CountedHandler(metricName, counted.active(), metricRegistry, route.getRouteHandler());
SortedMap<String, Gauge> gauges = metricRegistry.getGauges(); if (gauges.size() > 0) { writeGauges(gauges, writer); writer.newLine(); writeCounters(counters, writer); writer.newLine(); writeHistograms(histograms, writer); writer.newLine(); writeMeters(meters, writer); writer.newLine(); writeTimers(timers, writer);
registerAll("jvm.gc", new GarbageCollectorMetricSet()); registerAll("jvm.memory", new MemoryUsageGaugeSet()); registerAll("jvm.threads", new ThreadStatesGaugeSet()); registerAll("jvm.classes", new ClassLoadingGaugeSet()); reporter.start(pippoSettings, metricRegistry); reporters.add(reporter); MetricsDispatchListener metricsDispatchListener = new MetricsDispatchListener(metricRegistry); application.getRoutePreDispatchListeners().add(metricsDispatchListener); application.getRoutePostDispatchListeners().add(metricsDispatchListener); RouteTransformer transformer = new MetricsTransformer(metricRegistry); application.addRouteTransformer(transformer);
protected void writeTimer(Timer timer, BufferedWriter writer) throws IOException { writeMetered(timer, writer); writeSnapshot(timer.getSnapshot(), true, writer); }
protected void writeSnapshot(Snapshot snapshot, boolean duration, BufferedWriter writer) throws IOException { writeWithIndent("min = " + getSnapshotValueString(snapshot.getMin(), duration), writer); writeWithIndent("max = " + getSnapshotValueString(snapshot.getMax(), duration), writer); writeWithIndent("mean = " + getSnapshotValueString(snapshot.getMean(), duration), writer); writeWithIndent("stdDev = " + getSnapshotValueString(snapshot.getStdDev(), duration), writer); writeWithIndent("median = " + getSnapshotValueString(snapshot.getMedian(), duration), writer); writeWithIndent("75%% <= " + getSnapshotValueString(snapshot.get75thPercentile(), duration), writer); writeWithIndent("95%% <= " + getSnapshotValueString(snapshot.get95thPercentile(), duration), writer); writeWithIndent("98%% <= " + getSnapshotValueString(snapshot.get98thPercentile(), duration), writer); writeWithIndent("99%% <= " + getSnapshotValueString(snapshot.get99thPercentile(), duration), writer); writeWithIndent("99.9%% <= " + getSnapshotValueString(snapshot.get999thPercentile(), duration), writer); if (duration) { writeWithIndent("duration unit = " + durationUnit, writer); } }
protected void writeMeters(SortedMap<String, Meter> meters, BufferedWriter writer) throws IOException { writeBanner("Meters", writer); for (String key : meters.keySet()) { writer.write(key); writer.newLine(); writeMeter(meters.get(key), writer); } }
protected void writeHistograms(SortedMap<String, Histogram> histograms, BufferedWriter writer) throws IOException { writeBanner("Histograms", writer); for (String key : histograms.keySet()) { writer.write(key); writer.newLine(); writeHistogram(histograms.get(key), writer); writer.newLine(); } }
protected void writeTimers(SortedMap<String, Timer> timers, BufferedWriter writer) throws IOException { writeBanner("Timers", writer); for (String key : timers.keySet()) { writer.write(key); writer.newLine(); writeTimer(timers.get(key), writer); writer.newLine(); } }
protected void writeCounters(SortedMap<String, Counter> counters, BufferedWriter writer) throws IOException { writeBanner("Counters", writer); for (String key : counters.keySet()) { writer.write(key + " = " + counters.get(key).getCount()); writer.newLine(); } }
protected String getSnapshotValueString(double value, boolean duration) { return duration ? getDurationString(value) : String.valueOf(value); }
@Override public void onPostDispatch(Request request, Response response) { updateStatusCodeMetrics(response); activeRequests.dec(); }
protected void writeHistogram(Histogram histogram, BufferedWriter writer) throws IOException { writer.write(" count = " + histogram.getCount()); writer.newLine(); writeSnapshot(histogram.getSnapshot(), false, writer); }
private void registerAll(String prefix, MetricSet metrics) throws IllegalArgumentException { for (Map.Entry<String, Metric> entry : metrics.getMetrics().entrySet()) { if (entry.getValue() instanceof MetricSet) { registerAll(MetricRegistry.name(prefix, entry.getKey()), (MetricSet) entry.getValue()); } else { metricRegistry.register(MetricRegistry.name(prefix, entry.getKey()), entry.getValue()); } } }
protected String getDurationString(double value) { return toString(value * durationFactor); }
protected void writeMeter(Meter meter, BufferedWriter writer) throws IOException { writeMetered(meter, writer); }
protected void writeGauges(SortedMap<String, Gauge> gauges, BufferedWriter writer) throws IOException { writeBanner("Gauges", writer); for (String key : gauges.keySet()) { writer.write(key + " = " + gauges.get(key).getValue()); writer.newLine(); } }
protected String getDurationString(double value) { return toString(value * durationFactor); }