Search in sources :

Example 31 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)

Example 32 with MetricSnapshot

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

the class UIMetricUtils method getComponentMetric.

/**
 * get the specific component metric
 * @param info metric info
 * @param window window duration for metrics in seconds
 * @param compName component name
 * @param componentSummaries list of component summaries
 * @return the component metric
 */
public static UIComponentMetric getComponentMetric(MetricInfo info, int window, String compName, List<ComponentSummary> componentSummaries) {
    UIComponentMetric compMetric = new UIComponentMetric(compName);
    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 componentName = UIMetricUtils.extractComponentName(split_name);
            if (componentName != null && !componentName.equals(compName))
                continue;
            // only handle the specific component
            String metricName = UIMetricUtils.extractMetricName(split_name);
            String parentComp = null;
            if (metricName != null && metricName.contains(".")) {
                parentComp = metricName.split("\\.")[0];
                metricName = metricName.split("\\.")[1];
            }
            MetricSnapshot snapshot = metric.getValue().get(window);
            compMetric.setMetricValue(snapshot, parentComp, metricName);
        }
    }
    compMetric.mergeValue();
    ComponentSummary summary = null;
    for (ComponentSummary cs : componentSummaries) {
        if (cs.get_name().equals(compName)) {
            summary = cs;
            break;
        }
    }
    if (summary != null) {
        compMetric.setParallel(summary.get_parallel());
        compMetric.setType(summary.get_type());
    }
    return compMetric;
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot) ComponentSummary(backtype.storm.generated.ComponentSummary)

Example 33 with MetricSnapshot

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

the class UIMetricUtils method getTaskMetrics.

/**
 * get all task metrics in the specific component
 * @param info raw metric info
 * @param component component id
 * @param window window duration for metrics in seconds
 * @return the list of task metrics
 */
public static List<UITaskMetric> getTaskMetrics(MetricInfo info, String component, int window) {
    TreeMap<Integer, UITaskMetric> taskData = new TreeMap<>();
    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));
            String componentName = UIMetricUtils.extractComponentName(split_name);
            if (componentName != null && !componentName.equals(component))
                continue;
            // only handle the tasks belongs to the specific component
            String metricName = UIMetricUtils.extractMetricName(split_name);
            String parentComp = null;
            if (metricName != null && metricName.contains(".")) {
                parentComp = metricName.split("\\.")[0];
                metricName = metricName.split("\\.")[1];
            }
            if (!metric.getValue().containsKey(window)) {
                LOG.info("task snapshot {} missing window:{}", metric.getKey(), window);
                continue;
            }
            MetricSnapshot snapshot = metric.getValue().get(window);
            UITaskMetric taskMetric;
            if (taskData.containsKey(taskId)) {
                taskMetric = taskData.get(taskId);
            } else {
                taskMetric = new UITaskMetric(component, taskId);
                taskData.put(taskId, taskMetric);
            }
            taskMetric.setMetricValue(snapshot, parentComp, metricName);
        }
    }
    for (UITaskMetric t : taskData.values()) {
        t.mergeValue();
    }
    return new ArrayList<>(taskData.values());
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 34 with MetricSnapshot

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

the class UIMetricUtils method getTaskMetric.

/**
 * get the specific task metric
 * @param taskStreamMetrics raw metric info
 * @param component component name
 * @param id task id
 * @param window window duration for metrics in seconds
 * @return the task metric
 */
public static UITaskMetric getTaskMetric(List<MetricInfo> taskStreamMetrics, String component, int id, int window) {
    UITaskMetric taskMetric = new UITaskMetric(component, id);
    if (taskStreamMetrics.size() > 1) {
        MetricInfo info = taskStreamMetrics.get(0);
        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 parentComp = null;
                if (metricName != null && metricName.contains(".")) {
                    parentComp = metricName.split("\\.")[0];
                    metricName = metricName.split("\\.")[1];
                }
                MetricSnapshot snapshot = metric.getValue().get(window);
                taskMetric.setMetricValue(snapshot, parentComp, metricName);
            }
        }
    }
    taskMetric.mergeValue();
    return taskMetric;
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Example 35 with MetricSnapshot

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

the class UIMetricUtils method getWorkerMetrics.

public static List<UIWorkerMetric> getWorkerMetrics(MetricInfo info, String topology, int window) {
    Map<String, UIWorkerMetric> workerData = new HashMap<>();
    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);
            String port = UIMetricUtils.extractTaskId(split_name);
            String key = host + ":" + port;
            String metricName = UIMetricUtils.extractMetricName(split_name);
            if (!metric.getValue().containsKey(window)) {
                LOG.info("worker snapshot {} missing window:{}", metric.getKey(), window);
                continue;
            }
            MetricSnapshot snapshot = metric.getValue().get(window);
            UIWorkerMetric workerMetric;
            if (workerData.containsKey(key)) {
                workerMetric = workerData.get(key);
            } else {
                workerMetric = new UIWorkerMetric(host, port, topology);
                workerData.put(key, workerMetric);
            }
            workerMetric.setMetricValue(snapshot, metricName);
        }
    }
    return new ArrayList<>(workerData.values());
}
Also used : MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Aggregations

MetricSnapshot (backtype.storm.generated.MetricSnapshot)35 MetricInfo (backtype.storm.generated.MetricInfo)12 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)11 ConcurrentMap (java.util.concurrent.ConcurrentMap)11 Map (java.util.Map)7 HashMap (java.util.HashMap)6 JAverageSnapshot (com.alibaba.jstorm.common.metric.codahale.JAverageSnapshot)4 MetricType (com.alibaba.jstorm.metric.MetricType)3 TreeMap (java.util.TreeMap)3 ComponentSummary (backtype.storm.generated.ComponentSummary)2 TopologyMetric (backtype.storm.generated.TopologyMetric)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 ArrayList (java.util.ArrayList)2 Iface (backtype.storm.generated.Nimbus.Iface)1 WorkerSummary (backtype.storm.generated.WorkerSummary)1 NimbusClientWrapper (backtype.storm.utils.NimbusClientWrapper)1 KVSerializable (com.alibaba.jstorm.metric.KVSerializable)1