use of com.alibaba.jstorm.ui.model.UINettyMetric in project jstorm by alibaba.
the class NettyController method show.
@RequestMapping(value = "/netty", method = RequestMethod.GET)
public String show(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "topology", required = true) String topology_id, @RequestParam(value = "host", required = true) String host, @RequestParam(value = "page", required = false) String page, @RequestParam(value = "win", required = false) String win, ModelMap model) {
clusterName = StringEscapeUtils.escapeHtml(clusterName);
long start = System.currentTimeMillis();
host = NetWorkUtils.host2Ip(host);
int window = UIUtils.parseWindow(win);
UIUtils.addWindowAttribute(model, window);
int _page = JStormUtils.parseInt(page, 1);
NimbusClient client = null;
try {
client = NimbusClientManager.getNimbusClient(clusterName);
//get netty metrics, page is from 1
MetricInfo nettyMetric = client.getClient().getPagingNettyMetrics(topology_id, host, _page);
// System.out.println("nettyMetric:"+nettyMetric);
List<UINettyMetric> nettyData = getNettyData(nettyMetric, host, window);
model.addAttribute("nettyMetrics", nettyData);
model.addAttribute("nettyHead", UIMetricUtils.sortHead(nettyData, UINettyMetric.HEAD));
int size = client.getClient().getNettyMetricSizeByHost(topology_id, host);
// System.out.println("netty size:"+size);
int pageSize = (size + PAGE_SIZE - 1) / PAGE_SIZE;
model.addAttribute("pageSize", pageSize);
model.addAttribute("curPage", _page);
if (size == 0) {
//check whether netty metric is turn off
Map conf = UIUtils.getTopologyConf(clusterName, topology_id);
boolean enable = MetricUtils.isEnableNettyMetrics(conf);
if (!enable) {
model.addAttribute("flush", "the netty metrics is not enabled");
}
}
} catch (Exception e) {
NimbusClientManager.removeClient(clusterName);
LOG.error(e.getMessage(), e);
UIUtils.addErrorAttribute(model, e);
}
// page information
model.addAttribute("clusterName", clusterName);
model.addAttribute("host", host);
model.addAttribute("page", "netty");
model.addAttribute("topologyId", topology_id);
model.addAttribute("supervisorPort", UIUtils.getSupervisorPort(clusterName));
UIUtils.addTitleAttribute(model, "Netty Summary");
LOG.info("netty page show cost:{}ms", System.currentTimeMillis() - start);
return "netty";
}
use of com.alibaba.jstorm.ui.model.UINettyMetric 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());
}
Aggregations