use of com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot in project jstorm by alibaba.
the class MetricUtils method metricSnapshot2Histogram.
public static Histogram metricSnapshot2Histogram(MetricSnapshot snapshot) {
Histogram histogram;
if (metricAccurateCal) {
histogram = new Histogram(new ExponentiallyDecayingReservoir());
byte[] points = snapshot.get_points();
int len = snapshot.get_pointSize();
updateHistogramPoints(histogram, points, len);
} else {
histogram = new Histogram(new JAverageReservoir());
JAverageSnapshot averageSnapshot = (JAverageSnapshot) histogram.getSnapshot();
averageSnapshot.setMetricSnapshot(snapshot.deepCopy());
}
return histogram;
}
use of com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot in project jstorm by alibaba.
the class TopologyMetricContext method mergeHistograms.
/**
* histograms are sampled, but we just update points
*/
public void mergeHistograms(MetricInfo metricInfo, String meta, Map<Integer, MetricSnapshot> data, Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) {
Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
if (existing == null) {
metricInfo.put_to_metrics(meta, data);
Map<Integer, Histogram> histogramMap = new HashMap<>();
for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
Histogram histogram = MetricUtils.metricSnapshot2Histogram(dataEntry.getValue());
histogramMap.put(dataEntry.getKey(), histogram);
}
histograms.put(meta, histogramMap);
} else {
for (Map.Entry<Integer, MetricSnapshot> dataEntry : data.entrySet()) {
Integer win = dataEntry.getKey();
MetricSnapshot snapshot = dataEntry.getValue();
MetricSnapshot old = existing.get(win);
if (old == null) {
existing.put(win, snapshot);
histograms.get(meta).put(win, MetricUtils.metricSnapshot2Histogram(snapshot));
} else {
if (snapshot.get_ts() >= old.get_ts()) {
old.set_ts(snapshot.get_ts());
Histogram histogram = histograms.get(meta).get(win);
Snapshot updateSnapshot = histogram.getSnapshot();
if (updateSnapshot instanceof JAverageSnapshot) {
averageMetricSnapshot(((JAverageSnapshot) updateSnapshot).getMetricSnapshot(), snapshot);
} else {
// update points
MetricUtils.updateHistogramPoints(histogram, snapshot.get_points(), snapshot.get_pointSize());
}
}
}
}
}
updateMetricCounters(meta, metaCounters);
}
Aggregations