public LatencyMetric(T h) { Snapshot s = h.getSnapshot(); _min = h.min(); _max = h.max(); _mean = h.mean(); if (null != s) { _percentile95 = s.get95thPercentile(); _percentile99 = s.get99thPercentile(); _percentile999 = s.get999thPercentile(); } else { _percentile95 = -1; _percentile99 = -1; _percentile999 = -1; } _histogram = h; }
public double get95thPercentile() { return snapshot.get95thPercentile(); }
@Override public double get95thPercentile() { return metric.getSnapshot().get95thPercentile(); }
@Override public double get95thPercentile() { return metric.getSnapshot().get95thPercentile(); }
@Override public void processTimer(MetricName name, Timer timer, Context context) throws IOException { final PrintStream stream = context.getStream("# time,min,max,mean,median,stddev,95%,99%,99.9%"); final Snapshot snapshot = timer.getSnapshot(); stream.append(new StringBuilder() .append(timer.min()).append(',') .append(timer.max()).append(',') .append(timer.mean()).append(',') .append(snapshot.getMedian()).append(',') .append(timer.stdDev()).append(',') .append(snapshot.get95thPercentile()).append(',') .append(snapshot.get99thPercentile()).append(',') .append(snapshot.get999thPercentile()).toString()) .println(); stream.flush(); }
@Override public void processHistogram(MetricName name, Histogram histogram, Context context) throws IOException { final PrintStream stream = context.getStream("# time,min,max,mean,median,stddev,95%,99%,99.9%"); final Snapshot snapshot = histogram.getSnapshot(); stream.append(new StringBuilder() .append(histogram.min()).append(',') .append(histogram.max()).append(',') .append(histogram.mean()).append(',') .append(snapshot.getMedian()).append(',') .append(histogram.stdDev()).append(',') .append(snapshot.get95thPercentile()).append(',') .append(snapshot.get99thPercentile()).append(',') .append(snapshot.get999thPercentile()).toString()) .println(); stream.println(); stream.flush(); }
private static void writeSampling(Sampling metric, JsonGenerator json) throws IOException { final Snapshot snapshot = metric.getSnapshot(); json.writeNumberField("median", snapshot.getMedian()); json.writeNumberField("p75", snapshot.get75thPercentile()); json.writeNumberField("p95", snapshot.get95thPercentile()); json.writeNumberField("p98", snapshot.get98thPercentile()); json.writeNumberField("p99", snapshot.get99thPercentile()); json.writeNumberField("p999", snapshot.get999thPercentile()); }
/** @return an abbreviated summary of {@code hist}. */ public static String getShortHistogramReport(final Histogram hist) { Snapshot sn = hist.getSnapshot(); return "mean=" + DOUBLE_FORMAT.format(hist.mean()) + ", min=" + DOUBLE_FORMAT.format(hist.min()) + ", max=" + DOUBLE_FORMAT.format(hist.max()) + ", stdDev=" + DOUBLE_FORMAT.format(hist.stdDev()) + ", 95th=" + DOUBLE_FORMAT.format(sn.get95thPercentile()) + ", 99th=" + DOUBLE_FORMAT.format(sn.get99thPercentile()); }
@Override public void processHistogram(MetricName name, Histogram histogram, PrintStream stream) { final Snapshot snapshot = histogram.getSnapshot(); stream.printf(locale, " min = %2.2f\n", histogram.min()); stream.printf(locale, " max = %2.2f\n", histogram.max()); stream.printf(locale, " mean = %2.2f\n", histogram.mean()); stream.printf(locale, " stddev = %2.2f\n", histogram.stdDev()); stream.printf(locale, " median = %2.2f\n", snapshot.getMedian()); stream.printf(locale, " 75%% <= %2.2f\n", snapshot.get75thPercentile()); stream.printf(locale, " 95%% <= %2.2f\n", snapshot.get95thPercentile()); stream.printf(locale, " 98%% <= %2.2f\n", snapshot.get98thPercentile()); stream.printf(locale, " 99%% <= %2.2f\n", snapshot.get99thPercentile()); stream.printf(locale, " 99.9%% <= %2.2f\n", snapshot.get999thPercentile()); }
/** @return a summary of {@code hist}. */ public static String getHistogramReport(final Histogram hist) { Snapshot sn = hist.getSnapshot(); return ", mean=" + DOUBLE_FORMAT.format(hist.mean()) + ", min=" + DOUBLE_FORMAT.format(hist.min()) + ", max=" + DOUBLE_FORMAT.format(hist.max()) + ", stdDev=" + DOUBLE_FORMAT.format(hist.stdDev()) + ", 50th=" + DOUBLE_FORMAT.format(sn.getMedian()) + ", 75th=" + DOUBLE_FORMAT.format(sn.get75thPercentile()) + ", 95th=" + DOUBLE_FORMAT.format(sn.get95thPercentile()) + ", 99th=" + DOUBLE_FORMAT.format(sn.get99thPercentile()) + ", 99.9th=" + DOUBLE_FORMAT.format(sn.get999thPercentile()) + ", 99.99th=" + DOUBLE_FORMAT.format(sn.getValue(0.9999)) + ", 99.999th=" + DOUBLE_FORMAT.format(sn.getValue(0.99999)); } }
@Override public void processTimer(MetricName name, Timer timer, PrintStream stream) { processMeter(name, timer, stream); final String durationUnit = abbrev(timer.durationUnit()); final Snapshot snapshot = timer.getSnapshot(); stream.printf(locale, " min = %2.2f%s\n", timer.min(), durationUnit); stream.printf(locale, " max = %2.2f%s\n", timer.max(), durationUnit); stream.printf(locale, " mean = %2.2f%s\n", timer.mean(), durationUnit); stream.printf(locale, " stddev = %2.2f%s\n", timer.stdDev(), durationUnit); stream.printf(locale, " median = %2.2f%s\n", snapshot.getMedian(), durationUnit); stream.printf(locale, " 75%% <= %2.2f%s\n", snapshot.get75thPercentile(), durationUnit); stream.printf(locale, " 95%% <= %2.2f%s\n", snapshot.get95thPercentile(), durationUnit); stream.printf(locale, " 98%% <= %2.2f%s\n", snapshot.get98thPercentile(), durationUnit); stream.printf(locale, " 99%% <= %2.2f%s\n", snapshot.get99thPercentile(), durationUnit); stream.printf(locale, " 99.9%% <= %2.2f%s\n", snapshot.get999thPercentile(), durationUnit); }
private void addSnapshotDataObject(MetricName key, Histogram histogram, List<DataObject> dataObjectList) { Snapshot snapshot = histogram.getSnapshot(); dataObjectList.add(toDataObject(key, ".min", histogram.min())); dataObjectList.add(toDataObject(key, ".max", histogram.max())); dataObjectList.add(toDataObject(key, ".mean", histogram.mean())); dataObjectList.add(toDataObject(key, ".stddev", histogram.stdDev())); dataObjectList.add(toDataObject(key, ".median", snapshot.getMedian())); dataObjectList.add(toDataObject(key, ".75th", snapshot.get75thPercentile())); dataObjectList.add(toDataObject(key, ".95th", snapshot.get95thPercentile())); dataObjectList.add(toDataObject(key, ".98th", snapshot.get98thPercentile())); dataObjectList.add(toDataObject(key, ".99th", snapshot.get99thPercentile())); dataObjectList.add(toDataObject(key, ".99.9th", snapshot.get999thPercentile())); }
private void addSnapshotDataObjectWithConvertDuration(MetricName key, Timer timer, List<DataObject> dataObjectList) { Snapshot snapshot = timer.getSnapshot(); dataObjectList.add(toDataObject(key, ".min", convertDuration(timer.min()))); dataObjectList.add(toDataObject(key, ".max", convertDuration(timer.max()))); dataObjectList.add(toDataObject(key, ".mean", convertDuration(timer.mean()))); dataObjectList.add(toDataObject(key, ".stddev", convertDuration(timer.stdDev()))); dataObjectList.add(toDataObject(key, ".median", convertDuration(snapshot.getMedian()))); dataObjectList.add(toDataObject(key, ".75th", convertDuration(snapshot.get75thPercentile()))); dataObjectList.add(toDataObject(key, ".95th", convertDuration(snapshot.get95thPercentile()))); dataObjectList.add(toDataObject(key, ".98th", convertDuration(snapshot.get98thPercentile()))); dataObjectList.add(toDataObject(key, ".99th", convertDuration(snapshot.get99thPercentile()))); dataObjectList.add(toDataObject(key, ".99.9th", convertDuration(snapshot.get999thPercentile()))); }
@Override public String toString() { Snapshot snapshot = this.age.getSnapshot(); return "count=" + count + ", dataBlockCount=" + this.dataBlockCount + ", size=" + size + ", dataSize=" + getDataSize() + ", mean age=" + this.age.mean() + ", stddev age=" + this.age.stdDev() + ", min age=" + this.age.min() + ", max age=" + this.age.max() + ", 95th percentile age=" + snapshot.get95thPercentile() + ", 99th percentile age=" + snapshot.get99thPercentile(); } }
protected void sendSampling(long epoch, String sanitizedName, Sampling metric) throws IOException { final Snapshot snapshot = metric.getSnapshot(); sendFloat(epoch, sanitizedName, "median", snapshot.getMedian()); sendFloat(epoch, sanitizedName, "75percentile", snapshot.get75thPercentile()); sendFloat(epoch, sanitizedName, "95percentile", snapshot.get95thPercentile()); sendFloat(epoch, sanitizedName, "98percentile", snapshot.get98thPercentile()); sendFloat(epoch, sanitizedName, "99percentile", snapshot.get99thPercentile()); sendFloat(epoch, sanitizedName, "999percentile", snapshot.get999thPercentile()); }
private void pushSampling(MetricName name, Sampling sampling, Long epoch) { final Snapshot snapshot = sampling.getSnapshot(); pushGauge(name, snapshot.getMedian(), epoch, "median"); pushGauge(name, snapshot.get75thPercentile(), epoch, "75percentile"); pushGauge(name, snapshot.get95thPercentile(), epoch, "95percentile"); pushGauge(name, snapshot.get98thPercentile(), epoch, "98percentile"); pushGauge(name, snapshot.get99thPercentile(), epoch, "99percentile"); pushGauge(name, snapshot.get999thPercentile(), epoch, "999percentile"); }
@Override public void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { if (all || changed()) { clearChanged(); final Snapshot s = sample.getSnapshot(); metricsRecordBuilder.addCounter(name + NUM_OPS_METRIC_NAME, "", count.get()); metricsRecordBuilder.addGauge(name + MIN_METRIC_NAME, "", getMin()); metricsRecordBuilder.addGauge(name + MAX_METRIC_NAME, "", getMax()); metricsRecordBuilder.addGauge(name + MEAN_METRIC_NAME, "", getMean()); metricsRecordBuilder.addGauge(name + MEDIAN_METRIC_NAME, "", s.getMedian()); metricsRecordBuilder.addGauge(name + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME, "", s.get75thPercentile()); metricsRecordBuilder.addGauge(name + NINETY_FIFTH_PERCENTILE_METRIC_NAME, "", s.get95thPercentile()); metricsRecordBuilder.addGauge(name + NINETY_NINETH_PERCENTILE_METRIC_NAME, "", s.get99thPercentile()); } }
protected void sendSampling(String sanitizedName, Sampling metric) { final Snapshot snapshot = metric.getSnapshot(); sendToStatsD(sanitizedName + ".median", formatNumber(snapshot.getMedian())); sendToStatsD(sanitizedName + ".75percentile", formatNumber(snapshot.get75thPercentile())); sendToStatsD(sanitizedName + ".95percentile", formatNumber(snapshot.get95thPercentile())); sendToStatsD(sanitizedName + ".98percentile", formatNumber(snapshot.get98thPercentile())); sendToStatsD(sanitizedName + ".99percentile", formatNumber(snapshot.get99thPercentile())); sendToStatsD(sanitizedName + ".999percentile", formatNumber(snapshot.get999thPercentile())); }
@Override public void processHistogram(MetricName name, Histogram histogram, String x) throws IOException { final String sanitizedName = sanitizeName(name); final Snapshot snapshot = histogram.getSnapshot(); printDoubleField(sanitizedName + ".min", histogram.min(), "histo"); printDoubleField(sanitizedName + ".max", histogram.max(), "histo"); printDoubleField(sanitizedName + ".mean", histogram.mean(), "histo"); printDoubleField(sanitizedName + ".stddev", histogram.stdDev(), "histo"); printDoubleField(sanitizedName + ".median", snapshot.getMedian(), "histo"); printDoubleField(sanitizedName + ".75percentile", snapshot.get75thPercentile(), "histo"); printDoubleField(sanitizedName + ".95percentile", snapshot.get95thPercentile(), "histo"); printDoubleField(sanitizedName + ".98percentile", snapshot.get98thPercentile(), "histo"); printDoubleField(sanitizedName + ".99percentile", snapshot.get99thPercentile(), "histo"); printDoubleField(sanitizedName + ".999percentile", snapshot.get999thPercentile(), "histo"); }
@Override public void pushMetric(MetricsRecord mr) { final Snapshot s = this.getSnapshot(); mr.setMetric(getName() + NUM_OPS_METRIC_NAME, this.getCount()); mr.setMetric(getName() + MIN_METRIC_NAME, this.getMin()); mr.setMetric(getName() + MAX_METRIC_NAME, this.getMax()); mr.setMetric(getName() + MEAN_METRIC_NAME, (float) this.getMean()); mr.setMetric(getName() + STD_DEV_METRIC_NAME, (float) this.getStdDev()); mr.setMetric(getName() + MEDIAN_METRIC_NAME, (float) s.getMedian()); mr.setMetric(getName() + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME, (float) s.get75thPercentile()); mr.setMetric(getName() + NINETY_FIFTH_PERCENTILE_METRIC_NAME, (float) s.get95thPercentile()); mr.setMetric(getName() + NINETY_NINETH_PERCENTILE_METRIC_NAME, (float) s.get99thPercentile()); } }