Search in sources :

Example 1 with UINettyMetric

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";
}
Also used : MetricInfo(backtype.storm.generated.MetricInfo) UINettyMetric(com.alibaba.jstorm.ui.model.UINettyMetric) NimbusClient(backtype.storm.utils.NimbusClient) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UINettyMetric

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());
}
Also used : HashMap(java.util.HashMap) UINettyMetric(com.alibaba.jstorm.ui.model.UINettyMetric) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) MetricSnapshot(backtype.storm.generated.MetricSnapshot)

Aggregations

UINettyMetric (com.alibaba.jstorm.ui.model.UINettyMetric)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ModelMap (org.springframework.ui.ModelMap)2 MetricInfo (backtype.storm.generated.MetricInfo)1 MetricSnapshot (backtype.storm.generated.MetricSnapshot)1 NimbusClient (backtype.storm.utils.NimbusClient)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1