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