Search in sources :

Example 11 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class ClusterAPIController method metrics.

@RequestMapping("/metrics")
public Map metrics(@PathVariable String clusterName) {
    //we only get the 60s window
    int window = 60;
    Map ret;
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);
        List<MetricInfo> infos = client.getClient().getMetrics(JStormMetrics.CLUSTER_METRIC_KEY, MetaType.TOPOLOGY.getT());
        List<ChartSeries> metrics = UIUtils.getChartSeries(infos, window);
        ret = new HashMap<>();
        ret.put("metrics", metrics);
    } catch (Exception e) {
        NimbusClientManager.removeClient(clusterName);
        ret = UIUtils.exceptionJson(e);
        LOG.error(e.getMessage(), e);
    }
    return ret;
}
Also used : NimbusClient(backtype.storm.utils.NimbusClient) ChartSeries(com.alibaba.jstorm.ui.model.graph.ChartSeries) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class TopologyAPIController method graph.

@RequestMapping("/graph")
public Map graph(@PathVariable String clusterName, @PathVariable String topology) {
    Map<String, Object> result = new HashMap<>();
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);
        StormTopology stormTopology = client.getClient().getTopology(topology);
        int size = componentSize(stormTopology);
        if (size < 100) {
            List<MetricInfo> componentMetrics = client.getClient().getMetrics(topology, MetaType.COMPONENT.getT());
            TopologyGraph graph = UIUtils.getTopologyGraph(stormTopology, componentMetrics);
            result.put("graph", graph);
        } else {
            result.put("error", "too many components, please check your topology first!");
        }
    } catch (Exception e) {
        NimbusClientManager.removeClient(clusterName);
        LOG.error(e.getMessage(), e);
        result = UIUtils.exceptionJson(e);
    }
    return result;
}
Also used : TopologyGraph(com.alibaba.jstorm.ui.model.graph.TopologyGraph) NimbusClient(backtype.storm.utils.NimbusClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class ClusterController method show.

@RequestMapping(value = "/cluster", method = RequestMethod.GET)
public String show(@RequestParam(value = "name", required = true) String name, ModelMap model) {
    name = StringEscapeUtils.escapeHtml(name);
    long start = System.currentTimeMillis();
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(name);
        ClusterSummary clusterSummary = client.getClient().getClusterInfo();
        model.addAttribute("nimbus", UIUtils.getNimbusEntities(clusterSummary));
        model.addAttribute("topologies", UIUtils.getTopologyEntities(clusterSummary));
        model.addAttribute("supervisors", UIUtils.getSupervisorEntities(clusterSummary));
        model.addAttribute("zkServers", UIUtils.getZooKeeperEntities(name));
        List<MetricInfo> clusterMetrics = client.getClient().getMetrics(JStormMetrics.CLUSTER_METRIC_KEY, MetaType.TOPOLOGY.getT());
        UISummaryMetric clusterData = UIMetricUtils.getSummaryMetrics(clusterMetrics, AsmWindow.M1_WINDOW);
        model.addAttribute("clusterData", clusterData);
        model.addAttribute("clusterHead", UIMetricUtils.sortHead(clusterData, UISummaryMetric.HEAD));
        //update cluster cache
        ClusterEntity ce = UIUtils.getClusterEntity(clusterSummary, name);
        model.addAttribute("cluster", ce);
        UIUtils.clustersCache.put(name, ce);
    } catch (Exception e) {
        NimbusClientManager.removeClient(name);
        LOG.error(e.getMessage(), e);
        UIUtils.addErrorAttribute(model, e);
    }
    //set nimbus port and supervisor port , if necessary
    model.addAttribute("nimbusPort", UIUtils.getNimbusPort(name));
    model.addAttribute("supervisorPort", UIUtils.getSupervisorPort(name));
    model.addAttribute("clusterName", name);
    model.addAttribute("page", "cluster");
    UIUtils.addTitleAttribute(model, "Cluster Summary");
    LOG.info("cluster page show cost:{}ms", System.currentTimeMillis() - start);
    return "cluster";
}
Also used : NimbusClient(backtype.storm.utils.NimbusClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with NimbusClient

use of backtype.storm.utils.NimbusClient in project jstorm by alibaba.

the class LogController method deepSearch.

@RequestMapping(value = "/deepSearch", method = RequestMethod.GET)
public String deepSearch(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "tid", required = true) String topologyId, @RequestParam(value = "key", required = false) String keyword, @RequestParam(value = "caseIgnore", required = false) String caseIgnore, ModelMap model) {
    clusterName = StringEscapeUtils.escapeHtml(clusterName);
    topologyId = StringEscapeUtils.escapeHtml(topologyId);
    boolean _caseIgnore = !StringUtils.isBlank(caseIgnore);
    int port = UIUtils.getSupervisorPort(clusterName);
    model.addAttribute("keyword", keyword);
    List<Future<?>> futures = new ArrayList<>();
    ConcurrentLinkedQueue<Map> result = new ConcurrentLinkedQueue<>();
    if (filterKeyword(model, keyword)) {
        NimbusClient client = null;
        try {
            // encode space and url characters
            keyword = URLEncoder.encode(keyword, "UTF-8");
            client = NimbusClientManager.getNimbusClient(clusterName);
            TopologyInfo info = client.getClient().getTopologyInfo(topologyId);
            String topologyName = info.get_topology().get_name();
            List<UIWorkerMetric> workerData = UIMetricUtils.getWorkerMetrics(info.get_metrics().get_workerMetric(), topologyId, 60);
            String dir = "." + File.separator + topologyName;
            for (UIWorkerMetric metric : workerData) {
                String logFile = topologyName + "-worker-" + metric.getPort() + ".log";
                String url = String.format("http://%s:%s/logview?cmd=searchLog&file=%s&key=%s&offset=%s&case_ignore=%s", metric.getHost(), port, getFullFile(dir, logFile), keyword, 0, _caseIgnore);
                futures.add(_backround.submit(new SearchRequest(url, metric.getHost(), metric.getPort(), dir, logFile, result)));
            }
            JStormServerUtils.checkFutures(futures);
            model.addAttribute("result", result);
        } catch (NotAliveException nae) {
            model.addAttribute("tip", String.format("The topology: %s is dead.", topologyId));
        } catch (Exception e) {
            NimbusClientManager.removeClient(clusterName);
            LOG.error(e.getMessage(), e);
            UIUtils.addErrorAttribute(model, e);
        }
    }
    model.addAttribute("clusterName", clusterName);
    model.addAttribute("topologyId", topologyId);
    model.addAttribute("logServerPort", port);
    model.addAttribute("caseIgnore", _caseIgnore);
    UIUtils.addTitleAttribute(model, "DeepSearch");
    return "deepSearch";
}
Also used : UIWorkerMetric(com.alibaba.jstorm.ui.model.UIWorkerMetric) NimbusClient(backtype.storm.utils.NimbusClient) NotAliveException(backtype.storm.generated.NotAliveException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotAliveException(backtype.storm.generated.NotAliveException) ModelMap(org.springframework.ui.ModelMap) TopologyInfo(backtype.storm.generated.TopologyInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with NimbusClient

use of backtype.storm.utils.NimbusClient 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)

Aggregations

NimbusClient (backtype.storm.utils.NimbusClient)38 Map (java.util.Map)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 HashMap (java.util.HashMap)9 InvalidParameterException (java.security.InvalidParameterException)6 IOException (java.io.IOException)4 TException (org.apache.thrift.TException)4 ModelMap (org.springframework.ui.ModelMap)4 ClusterSummary (backtype.storm.generated.ClusterSummary)3 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)3 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)3 NimbusInfo (backtype.storm.nimbus.NimbusInfo)3 FileNotFoundException (java.io.FileNotFoundException)3 TTransportException (org.apache.thrift.transport.TTransportException)3 KillOptions (backtype.storm.generated.KillOptions)2 MetricInfo (backtype.storm.generated.MetricInfo)2 TopologyInfo (backtype.storm.generated.TopologyInfo)2 UITaskMetric (com.alibaba.jstorm.ui.model.UITaskMetric)2 UIWorkerMetric (com.alibaba.jstorm.ui.model.UIWorkerMetric)2 ChartSeries (com.alibaba.jstorm.ui.model.graph.ChartSeries)2