use of com.codahale.metrics.Snapshot in project gerrit by GerritCodeReview.
the class MetricJson method init.
private void init(Metric metric, ImmutableMap<String, String> atts) {
if (metric instanceof BucketedMetric) {
BucketedMetric m = (BucketedMetric) metric;
if (m.getTotal() != null) {
init(m.getTotal(), atts);
}
Field<?>[] fieldList = m.getFields();
fields = new ArrayList<>(fieldList.length);
for (Field<?> f : fieldList) {
fields.add(new FieldJson(f));
}
buckets = makeBuckets(fieldList, m.getCells(), atts);
} else if (metric instanceof Counter) {
Counter c = (Counter) metric;
count = c.getCount();
} else if (metric instanceof Gauge) {
Gauge<?> g = (Gauge<?>) metric;
value = g.getValue();
} else if (metric instanceof Meter) {
Meter m = (Meter) metric;
count = m.getCount();
rate_1m = m.getOneMinuteRate();
rate_5m = m.getFiveMinuteRate();
rate_15m = m.getFifteenMinuteRate();
} else if (metric instanceof Timer) {
Timer m = (Timer) metric;
Snapshot s = m.getSnapshot();
count = m.getCount();
rate_1m = m.getOneMinuteRate();
rate_5m = m.getFiveMinuteRate();
rate_15m = m.getFifteenMinuteRate();
double div = Description.getTimeUnit(atts.get(Description.UNIT)).toNanos(1);
p50 = s.getMedian() / div;
p75 = s.get75thPercentile() / div;
p95 = s.get95thPercentile() / div;
p98 = s.get98thPercentile() / div;
p99 = s.get99thPercentile() / div;
p99_9 = s.get999thPercentile() / div;
min = s.getMin() / div;
max = s.getMax() / div;
std_dev = s.getStdDev() / div;
} else if (metric instanceof Histogram) {
Histogram m = (Histogram) metric;
Snapshot s = m.getSnapshot();
count = m.getCount();
p50 = s.getMedian();
p75 = s.get75thPercentile();
p95 = s.get95thPercentile();
p98 = s.get98thPercentile();
p99 = s.get99thPercentile();
p99_9 = s.get999thPercentile();
min = (double) s.getMin();
avg = s.getMean();
max = (double) s.getMax();
sum = s.getMean() * m.getCount();
std_dev = s.getStdDev();
}
}
use of com.codahale.metrics.Snapshot in project hbase by apache.
the class TestPerformanceEvaluation method testZipfian.
@Test
public void testZipfian() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
TestOptions opts = new PerformanceEvaluation.TestOptions();
opts.setValueZipf(true);
final int valueSize = 1024;
opts.setValueSize(valueSize);
RandomReadTest rrt = new RandomReadTest(null, opts, null);
Constructor<?> ctor = Histogram.class.getDeclaredConstructor(com.codahale.metrics.Reservoir.class);
ctor.setAccessible(true);
Histogram histogram = (Histogram) ctor.newInstance(new UniformReservoir(1024 * 500));
for (int i = 0; i < 100; i++) {
histogram.update(rrt.getValueLength(null));
}
Snapshot snapshot = histogram.getSnapshot();
double stddev = snapshot.getStdDev();
assertTrue(stddev != 0 && stddev != 1.0);
assertTrue(snapshot.getStdDev() != 0);
double median = snapshot.getMedian();
assertTrue(median != 0 && median != 1 && median != valueSize);
}
use of com.codahale.metrics.Snapshot in project chassis by Kixeye.
the class MetricsCloudWatchReporter method addHistograms.
private void addHistograms(SortedMap<String, Histogram> histograms, LinkedList<PutMetricDataRequest> requests, Date timestamp) {
logger.debug("Adding Histograms...");
for (String name : histograms.keySet()) {
Histogram histogram = histograms.get(name);
Snapshot snapshot = histogram.getSnapshot();
checkAndAddDatum(MetricFilter.Stat.COUNT, name, histogram.getCount(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.MIN, name, snapshot.getMin(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.MAX, name, snapshot.getMax(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.MEAN, name, snapshot.getMean(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.STDDEV, name, snapshot.getStdDev(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.PERCENTILE_75, name, snapshot.get75thPercentile(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.PERCENTILE_95, name, snapshot.get95thPercentile(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.PERCENTILE_98, name, snapshot.get98thPercentile(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.PERCENTILE_99, name, snapshot.get99thPercentile(), requests, timestamp);
checkAndAddDatum(MetricFilter.Stat.PERCENTILE_999, name, snapshot.get999thPercentile(), requests, timestamp);
}
}
use of com.codahale.metrics.Snapshot in project newts by OpenNMS.
the class NewtsReporter method reportTimer.
private void reportTimer(List<Sample> samples, Timestamp timestamp, String name, Timer timer) {
final Snapshot snapshot = timer.getSnapshot();
Map<String, String> rateAttr = Maps.newHashMap();
rateAttr.put("rate_unit", getRateUnit());
Map<String, String> durationAttr = Maps.newHashMap();
durationAttr.put("duration_unit", getDurationUnit());
reportC(samples, timestamp, name, "count", timer.getCount());
reportG(samples, timestamp, name, "max", convertDuration(snapshot.getMax()), durationAttr);
reportG(samples, timestamp, name, "mean", convertDuration(snapshot.getMean()), durationAttr);
reportG(samples, timestamp, name, "min", convertDuration(snapshot.getMin()), durationAttr);
reportG(samples, timestamp, name, "stddev", convertDuration(snapshot.getStdDev()), durationAttr);
reportG(samples, timestamp, name, "p50", convertDuration(snapshot.getMedian()), durationAttr);
reportG(samples, timestamp, name, "p75", convertDuration(snapshot.get75thPercentile()), durationAttr);
reportG(samples, timestamp, name, "p95", convertDuration(snapshot.get95thPercentile()), durationAttr);
reportG(samples, timestamp, name, "p98", convertDuration(snapshot.get98thPercentile()), durationAttr);
reportG(samples, timestamp, name, "p99", convertDuration(snapshot.get99thPercentile()), durationAttr);
reportG(samples, timestamp, name, "p999", convertDuration(snapshot.get999thPercentile()), durationAttr);
reportG(samples, timestamp, name, "mean_rate", convertRate(timer.getMeanRate()), rateAttr);
reportG(samples, timestamp, name, "m1_rate", convertRate(timer.getOneMinuteRate()), rateAttr);
reportG(samples, timestamp, name, "m5_rate", convertRate(timer.getFiveMinuteRate()), rateAttr);
reportG(samples, timestamp, name, "m15_rate", convertRate(timer.getFifteenMinuteRate()), rateAttr);
}
use of com.codahale.metrics.Snapshot in project jstorm by alibaba.
the class TopologyMetricContext method adjustMetrics.
private void adjustMetrics(Map<String, Map<Integer, MetricSnapshot>> metrics, Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) {
for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metrics.entrySet()) {
String meta = metricEntry.getKey();
MetricType metricType = MetricUtils.metricType(meta);
MetaType metaType = MetricUtils.metaType(meta);
Map<Integer, MetricSnapshot> winData = metricEntry.getValue();
if (metricType == MetricType.HISTOGRAM) {
for (Map.Entry<Integer, MetricSnapshot> dataEntry : winData.entrySet()) {
MetricSnapshot snapshot = dataEntry.getValue();
Integer cnt = metaCounters.get(meta);
Histogram histogram = histograms.get(meta).get(dataEntry.getKey());
if (cnt != null && cnt > 1) {
int denominator = 1;
if (!MetricUtils.metricAccurateCal)
denominator = cnt;
Snapshot snapshot1 = histogram.getSnapshot();
snapshot.set_mean(snapshot1.getMean() / denominator);
snapshot.set_p50(snapshot1.getMedian() / denominator);
snapshot.set_p75(snapshot1.get75thPercentile() / denominator);
snapshot.set_p95(snapshot1.get95thPercentile() / denominator);
snapshot.set_p98(snapshot1.get98thPercentile() / denominator);
snapshot.set_p99(snapshot1.get99thPercentile() / denominator);
snapshot.set_p999(snapshot1.get999thPercentile() / denominator);
snapshot.set_stddev(snapshot1.getStdDev() / denominator);
snapshot.set_min(snapshot1.getMin() / denominator);
snapshot.set_max(snapshot1.getMax() / denominator);
if (MetricUtils.metricAccurateCal && metaType == MetaType.TOPOLOGY) {
snapshot.set_points(MetricUtils.longs2bytes(snapshot1.getValues()));
}
}
if (metaType != MetaType.TOPOLOGY || !MetricUtils.metricAccurateCal) {
snapshot.set_points(new byte[0]);
}
}
}
}
}
Aggregations