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());
}
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;
}
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());
}
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;
}
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());
}
Aggregations