Search in sources :

Example 11 with MetricSnapshot

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

the class TopologyMetricContext method resetPoints.

private void resetPoints(Map<String, Map<Integer, MetricSnapshot>> metrics) {
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metrics.entrySet()) {
        String meta = metricEntry.getKey();
        MetricType metricType = MetricUtils.metricType(meta);
        Map<Integer, MetricSnapshot> winData = metricEntry.getValue();
        if (metricType == MetricType.HISTOGRAM) {
            for (MetricSnapshot snapshot : winData.values()) {
                snapshot.set_points(new byte[0]);
            }
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 12 with MetricSnapshot

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

the class ServiceHandler method getPagingNettyMetrics.

@Override
public MetricInfo getPagingNettyMetrics(String topologyId, String host, int page) throws TException {
    MetricInfo ret = new MetricInfo();
    int start = (page - 1) * MetricUtils.NETTY_METRIC_PAGE_SIZE;
    int end = page * MetricUtils.NETTY_METRIC_PAGE_SIZE;
    int cur = -1;
    List<MetricInfo> metricInfoList = data.getMetricCache().getMetricData(topologyId, MetaType.NETTY);
    if (metricInfoList != null && metricInfoList.size() > 0) {
        MetricInfo metricInfo = metricInfoList.get(0);
        for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metricInfo.get_metrics().entrySet()) {
            String metricName = metricEntry.getKey();
            Map<Integer, MetricSnapshot> data = metricEntry.getValue();
            if (metricName.contains(host)) {
                ++cur;
                if (cur >= start && cur < end) {
                    ret.put_to_metrics(metricName, data);
                }
                if (cur >= end) {
                    break;
                }
            }
        }
    }
    LOG.info("getNettyMetricsByHost, total size:{}", ret.get_metrics_size());
    return ret;
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 13 with MetricSnapshot

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

the class ServiceHandler method getNettyMetricsByHost.

@Override
public MetricInfo getNettyMetricsByHost(String topologyId, String host) throws TException {
    MetricInfo ret = new MetricInfo();
    List<MetricInfo> metricInfoList = data.getMetricCache().getMetricData(topologyId, MetaType.NETTY);
    if (metricInfoList != null && metricInfoList.size() > 0) {
        MetricInfo metricInfo = metricInfoList.get(0);
        for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metricInfo.get_metrics().entrySet()) {
            String metricName = metricEntry.getKey();
            Map<Integer, MetricSnapshot> data = metricEntry.getValue();
            if (metricName.contains(host)) {
                ret.put_to_metrics(metricName, data);
            }
        }
    }
    LOG.info("getNettyMetricsByHost, total size:{}", ret.get_metrics_size());
    return ret;
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 14 with MetricSnapshot

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

the class UpdateEvent method updateClusterMetrics.

//update cluster metrics local cache
private void updateClusterMetrics(String topologyId, TopologyMetric tpMetric) {
    if (tpMetric.get_topologyMetric().get_metrics_size() == 0) {
        return;
    }
    MetricInfo topologyMetrics = tpMetric.get_topologyMetric();
    // make a new MetricInfo to save the topologyId's metric
    MetricInfo clusterMetrics = MetricUtils.mkMetricInfo();
    Set<String> metricNames = new HashSet<>();
    for (Map.Entry<String, Map<Integer, MetricSnapshot>> entry : topologyMetrics.get_metrics().entrySet()) {
        String metricName = MetricUtils.topo2clusterName(entry.getKey());
        MetricType metricType = MetricUtils.metricType(metricName);
        Map<Integer, MetricSnapshot> winData = new HashMap<>();
        for (Map.Entry<Integer, MetricSnapshot> entryData : entry.getValue().entrySet()) {
            MetricSnapshot snapshot = entryData.getValue().deepCopy();
            winData.put(entryData.getKey(), snapshot);
            if (metricType == MetricType.HISTOGRAM) {
                // reset topology metric points
                entryData.getValue().set_points(new byte[0]);
                entryData.getValue().set_pointSize(0);
            }
        }
        clusterMetrics.put_to_metrics(metricName, winData);
        metricNames.add(metricName);
    }
    // save to local cache, waiting for merging
    TopologyMetricContext clusterTpMetricContext = context.getClusterTopologyMetricContext();
    clusterTpMetricContext.addToMemCache(topologyId, clusterMetrics);
    context.registerMetrics(JStormMetrics.CLUSTER_METRIC_KEY, metricNames);
}
Also used : HashMap(java.util.HashMap) MetricType(com.alibaba.jstorm.metric.MetricType) TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext) MetricInfo(backtype.storm.generated.MetricInfo) HashMap(java.util.HashMap) Map(java.util.Map) MetricSnapshot(backtype.storm.generated.MetricSnapshot) HashSet(java.util.HashSet)

Example 15 with MetricSnapshot

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

the class UIMetricUtils method getWorkerMetrics.

public static List<UIWorkerMetric> getWorkerMetrics(Map<String, MetricInfo> workerMetricInfo, List<WorkerSummary> workerSummaries, String host, int window) {
    Map<String, UIWorkerMetric> workerMetrics = new HashMap<>();
    for (MetricInfo info : workerMetricInfo.values()) {
        if (info != null) {
            for (Map.Entry<String, Map<Integer, MetricSnapshot>> metric : info.get_metrics().entrySet()) {
                String name = metric.getKey();
                String[] split_name = name.split("@");
                String _host = UIMetricUtils.extractComponentName(split_name);
                if (!host.equals(_host))
                    continue;
                //only handle the specific host
                String port = UIMetricUtils.extractTaskId(split_name);
                String key = host + ":" + port;
                String metricName = UIMetricUtils.extractMetricName(split_name);
                MetricSnapshot snapshot = metric.getValue().get(window);
                UIWorkerMetric workerMetric;
                if (workerMetrics.containsKey(key)) {
                    workerMetric = workerMetrics.get(key);
                } else {
                    workerMetric = new UIWorkerMetric(host, port);
                    workerMetrics.put(key, workerMetric);
                }
                workerMetric.setMetricValue(snapshot, metricName);
            }
        }
    }
    for (WorkerSummary ws : workerSummaries) {
        String worker = host + ":" + ws.get_port();
        if (workerMetrics.containsKey(worker)) {
            workerMetrics.get(worker).setTopology(ws.get_topology());
        }
    }
    return new ArrayList<>(workerMetrics.values());
}
Also used : WorkerSummary(backtype.storm.generated.WorkerSummary) 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