Search in sources :

Example 21 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot 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)

Example 22 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class TopologyMetricContext method mergeGauges.

public void mergeGauges(TopologyMetric tpMetric, MetaType metaType, String meta, Map<Integer, MetricSnapshot> data) {
    MetricInfo metricInfo = getMetricInfoByType(tpMetric, metaType);
    Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
    if (existing == null) {
        metricInfo.put_to_metrics(meta, data);
    } 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);
            } else {
                if (snapshot.get_ts() >= old.get_ts()) {
                    old.set_ts(snapshot.get_ts());
                    if (metaType != MetaType.TOPOLOGY) {
                        old.set_doubleValue(snapshot.get_doubleValue());
                    } else {
                        // for topology metric, gauge might be add-able, e.g., cpu, memory, etc.
                        old.set_doubleValue(old.get_doubleValue() + snapshot.get_doubleValue());
                    }
                }
            }
        }
    }
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) MetricSnapshot(backtype.storm.generated.MetricSnapshot) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 23 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class TopologyMetricContext method mergeMeters.

/**
     * meters are not sampled.
     */
public void mergeMeters(MetricInfo metricInfo, String meta, Map<Integer, MetricSnapshot> data, Map<String, Integer> metaCounters) {
    Map<Integer, MetricSnapshot> existing = metricInfo.get_metrics().get(meta);
    if (existing == null) {
        metricInfo.put_to_metrics(meta, data);
    } 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);
            } else {
                if (snapshot.get_ts() >= old.get_ts()) {
                    old.set_ts(snapshot.get_ts());
                    old.set_mean(old.get_mean() + snapshot.get_mean());
                    old.set_m1(old.get_m1() + snapshot.get_m1());
                    old.set_m5(old.get_m5() + snapshot.get_m5());
                    old.set_m15(old.get_m15() + snapshot.get_m15());
                }
            }
        }
    }
    updateMetricCounters(meta, metaCounters);
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 24 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class NettyController method getNettyData.

private List<UINettyMetric> getNettyData(MetricInfo nettyMetrics, String host, int window) {
    HashMap<String, UINettyMetric> nettyData = new HashMap<>();
    if (nettyMetrics == null || nettyMetrics.get_metrics_size() == 0) {
        return new ArrayList<>(nettyData.values());
    }
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> metric : nettyMetrics.get_metrics().entrySet()) {
        String name = metric.getKey();
        String[] split_name = name.split("@");
        String metricName = UIMetricUtils.extractMetricName(split_name);
        String connection = null;
        if (metricName != null) {
            connection = metricName.substring(metricName.indexOf(".") + 1);
            metricName = metricName.substring(0, metricName.indexOf("."));
        }
        MetricSnapshot snapshot = metric.getValue().get(window);
        UINettyMetric netty;
        if (nettyData.containsKey(connection)) {
            netty = nettyData.get(connection);
        } else {
            netty = new UINettyMetric(host, connection);
            nettyData.put(connection, netty);
        }
        netty.setMetricValue(snapshot, metricName);
    }
    return new ArrayList<>(nettyData.values());
}
Also used : HashMap(java.util.HashMap) UINettyMetric(com.alibaba.jstorm.ui.model.UINettyMetric) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 25 with MetricSnapshot

use of backtype.storm.generated.MetricSnapshot in project jstorm by alibaba.

the class UIMetricUtils method getStreamMetrics.

public static List<UIStreamMetric> getStreamMetrics(List<MetricInfo> taskStreamMetrics, String component, int id, int window) {
    Map<String, UIStreamMetric> streamData = new HashMap<>();
    if (taskStreamMetrics.size() > 1) {
        MetricInfo info = taskStreamMetrics.get(1);
        if (info != null) {
            for (Map.Entry<String, Map<Integer, MetricSnapshot>> metric : info.get_metrics().entrySet()) {
                String name = metric.getKey();
                String[] split_name = name.split("@");
                int taskId = JStormUtils.parseInt(UIMetricUtils.extractTaskId(split_name));
                if (taskId != id)
                    continue;
                //only handle the specific task
                String metricName = UIMetricUtils.extractMetricName(split_name);
                String streamId = UIMetricUtils.extractStreamId(split_name);
                String parentComp = null;
                if (metricName != null && metricName.contains(".")) {
                    parentComp = metricName.split("\\.")[0];
                    metricName = metricName.split("\\.")[1];
                }
                MetricSnapshot snapshot = metric.getValue().get(window);
                UIStreamMetric streamMetric;
                if (streamData.containsKey(streamId)) {
                    streamMetric = streamData.get(streamId);
                } else {
                    streamMetric = new UIStreamMetric(component, streamId);
                    streamData.put(streamId, streamMetric);
                }
                streamMetric.setMetricValue(snapshot, parentComp, metricName);
            }
        }
    }
    for (UIStreamMetric stream : streamData.values()) {
        stream.mergeValue();
    }
    return new ArrayList<>(streamData.values());
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Aggregations

MetricSnapshot (backtype.storm.generated.MetricSnapshot)30 MetricInfo (backtype.storm.generated.MetricInfo)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ConcurrentMap (java.util.concurrent.ConcurrentMap)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)4 TreeMap (java.util.TreeMap)3 ComponentSummary (backtype.storm.generated.ComponentSummary)2 TopologyMetric (backtype.storm.generated.TopologyMetric)2 MetricType (com.alibaba.jstorm.metric.MetricType)2 TopologyMetricContext (com.alibaba.jstorm.metric.TopologyMetricContext)2 TimeCacheMap (com.alibaba.jstorm.utils.TimeCacheMap)2 Histogram (com.codahale.metrics.Histogram)2 Snapshot (com.codahale.metrics.Snapshot)2 Iface (backtype.storm.generated.Nimbus.Iface)1 WorkerSummary (backtype.storm.generated.WorkerSummary)1 NimbusClientWrapper (backtype.storm.utils.NimbusClientWrapper)1 UINettyMetric (com.alibaba.jstorm.ui.model.UINettyMetric)1 IOException (java.io.IOException)1