Search in sources :

Example 1 with UIWorkerMetric

use of com.alibaba.jstorm.ui.model.UIWorkerMetric 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 2 with UIWorkerMetric

use of com.alibaba.jstorm.ui.model.UIWorkerMetric in project jstorm by alibaba.

the class SupervisorController method show.

@RequestMapping(value = "/supervisor", method = RequestMethod.GET)
public String show(@RequestParam(value = "cluster", required = true) String clusterName, @RequestParam(value = "host", required = true) String host, @RequestParam(value = "win", required = false) String win, ModelMap model) {
    if (UIUtils.isValidSupervisorHost(clusterName, host)) {
        UIUtils.addErrorAttribute(model, new RuntimeException("Not a valid host: " + host));
        return "supervisor";
    }
    clusterName = StringEscapeUtils.escapeHtml(clusterName);
    long start = System.currentTimeMillis();
    host = NetWorkUtils.host2Ip(host);
    int window = UIUtils.parseWindow(win);
    UIUtils.addWindowAttribute(model, window);
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);
        // get supervisor summary
        SupervisorWorkers supervisorWorkers = client.getClient().getSupervisorWorkers(host);
        model.addAttribute("supervisor", new SupervisorEntity(supervisorWorkers.get_supervisor()));
        // get worker summary
        List<WorkerSummary> workerSummaries = supervisorWorkers.get_workers();
        model.addAttribute("workerSummary", UIUtils.getWorkerEntities(workerSummaries));
        // get worker metrics
        Map<String, MetricInfo> workerMetricInfo = supervisorWorkers.get_workerMetric();
        List<UIWorkerMetric> workerMetrics = UIMetricUtils.getWorkerMetrics(workerMetricInfo, workerSummaries, host, window);
        // System.out.println("workerMetricInfo:"+workerMetricInfo);
        model.addAttribute("workerMetrics", workerMetrics);
        model.addAttribute("workerHead", UIMetricUtils.sortHead(workerMetrics, UIWorkerMetric.HEAD));
    } 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", "supervisor");
    model.addAttribute("supervisorPort", UIUtils.getSupervisorPort(clusterName));
    UIUtils.addTitleAttribute(model, "Supervisor Summary");
    LOG.info("supervisor page show cost:{}ms", System.currentTimeMillis() - start);
    return "supervisor";
}
Also used : UIWorkerMetric(com.alibaba.jstorm.ui.model.UIWorkerMetric) NimbusClient(backtype.storm.utils.NimbusClient) SupervisorEntity(com.alibaba.jstorm.ui.model.SupervisorEntity) WorkerSummary(backtype.storm.generated.WorkerSummary) MetricInfo(backtype.storm.generated.MetricInfo) SupervisorWorkers(backtype.storm.generated.SupervisorWorkers) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NimbusClient (backtype.storm.utils.NimbusClient)2 UIWorkerMetric (com.alibaba.jstorm.ui.model.UIWorkerMetric)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 MetricInfo (backtype.storm.generated.MetricInfo)1 NotAliveException (backtype.storm.generated.NotAliveException)1 SupervisorWorkers (backtype.storm.generated.SupervisorWorkers)1 TopologyInfo (backtype.storm.generated.TopologyInfo)1 WorkerSummary (backtype.storm.generated.WorkerSummary)1 SupervisorEntity (com.alibaba.jstorm.ui.model.SupervisorEntity)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ModelMap (org.springframework.ui.ModelMap)1