Search in sources :

Example 1 with JAverageSnapshot

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;
}
Also used : JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) JAverageReservoir(com.alibaba.jstorm.common.metric.codahale.JAverageReservoir)

Example 2 with JAverageSnapshot

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);
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot) Snapshot(com.codahale.metrics.Snapshot) JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) Histogram(com.codahale.metrics.Histogram) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JAverageSnapshot(com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot) MetricSnapshot(backtype.storm.generated.MetricSnapshot) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)2 MetricSnapshot (backtype.storm.generated.MetricSnapshot)1 JAverageReservoir (com.alibaba.jstorm.common.metric.codahale.JAverageReservoir)1 Histogram (com.codahale.metrics.Histogram)1 Snapshot (com.codahale.metrics.Snapshot)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1