public void run(String hostname) { try { getMonitorLock(); } catch (Exception e) { log.error("Failed to get Monitor ZooKeeper lock"); throw new RuntimeException(e); } Monitor.START_TIME = System.currentTimeMillis(); int port = config.getConfiguration().getPort(Property.MONITOR_PORT); try { log.debug("Creating monitor on port " + port); server = new EmbeddedWebServer(hostname, port); } catch (Throwable ex) { log.error("Unable to start embedded web server", ex); throw new RuntimeException(ex); } server.addServlet(DefaultServlet.class, "/"); server.addServlet(OperationServlet.class, "/op"); server.addServlet(MasterServlet.class, "/master"); server.addServlet(TablesServlet.class, "/tables"); server.addServlet(TServersServlet.class, "/tservers"); server.addServlet(ProblemServlet.class, "/problems"); server.addServlet(GcStatusServlet.class, "/gc"); server.addServlet(LogServlet.class, "/log"); server.addServlet(XMLServlet.class, "/xml"); server.addServlet(JSONServlet.class, "/json"); server.addServlet(VisServlet.class, "/vis"); server.addServlet(Summary.class, "/trace/summary"); server.addServlet(ListType.class, "/trace/listType"); server.addServlet(ShowTrace.class, "/trace/show"); if (server.isUsingSsl()) server.addServlet(ShellServlet.class, "/shell"); server.start(); try { hostname = InetAddress.getLocalHost().getHostName(); log.debug("Using " + hostname + " to advertise monitor location in ZooKeeper"); String monitorAddress = HostAndPort.fromParts(hostname, server.getPort()).toString(); ZooReaderWriter.getInstance() .putPersistentData( ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR, monitorAddress.getBytes(StandardCharsets.UTF_8), NodeExistsPolicy.OVERWRITE); log.info("Set monitor address in zookeeper to " + monitorAddress); } catch (Exception ex) { log.error("Unable to set monitor HTTP address in zookeeper", ex); } if (null != hostname) { LogService.startLogListener( Monitor.getSystemConfiguration(), instance.getInstanceID(), hostname); } else { log.warn("Not starting log4j listener as we could not determine address to use"); } new Daemon(new LoggingRunnable(log, new ZooKeeperStatus()), "ZooKeeperStatus").start(); // need to regularly fetch data so plot data is updated new Daemon( new LoggingRunnable( log, new Runnable() { @Override public void run() { while (true) { try { Monitor.fetchData(); } catch (Exception e) { log.warn(e.getMessage(), e); } UtilWaitThread.sleep(333); } } }), "Data fetcher") .start(); }
protected void pageStart(HttpServletRequest req, HttpServletResponse resp, StringBuilder sb) throws Exception { resp.setContentType(DEFAULT_CONTENT_TYPE); int refresh = -1; Cookie c = getCookie(req, "page.refresh.rate"); if (c != null && c.getValue() != null) { try { refresh = Integer.parseInt(c.getValue()); } catch (NumberFormatException e) { // ignore improperly formatted user cookie } } synchronized (BasicServlet.class) { // Learn our instance name asynchronously so we don't hang up if zookeeper is down if (cachedInstanceName == null) { SimpleTimer.getInstance() .schedule( new TimerTask() { @Override public void run() { synchronized (BasicServlet.class) { if (cachedInstanceName == null) { cachedInstanceName = HdfsZooInstance.getInstance().getInstanceName(); } } } }, 1000); } } // BEGIN PAGE sb.append("<html>\n"); // BEGIN HEADER sb.append("<head>\n"); sb.append("<title>") .append(getTitle(req)) .append(" - Accumulo ") .append(Constants.VERSION) .append("</title>\n"); if ((refresh > 0) && (req.getRequestURI().startsWith("/docs") == false) && (req.getRequestURI().startsWith("/vis") == false)) sb.append("<meta http-equiv='refresh' content='" + refresh + "' />\n"); sb.append("<meta http-equiv='Content-Type' content='") .append(DEFAULT_CONTENT_TYPE) .append("' />\n"); sb.append("<meta http-equiv='Content-Script-Type' content='text/javascript' />\n"); sb.append("<meta http-equiv='Content-Style-Type' content='text/css' />\n"); sb.append("<link rel='shortcut icon' type='image/jpg' href='/web/favicon.png' />\n"); sb.append("<link rel='stylesheet' type='text/css' href='/web/screen.css' media='screen' />\n"); sb.append("<script src='/web/functions.js' type='text/javascript'></script>\n"); sb.append( "<!--[if lte IE 8]><script language=\"javascript\" type=\"text/javascript\" src=\"/web/flot/excanvas.min.js\"></script><![endif]-->\n"); sb.append( "<script language=\"javascript\" type=\"text/javascript\" src=\"/web/flot/jquery.js\"></script>\n"); sb.append( "<script language=\"javascript\" type=\"text/javascript\" src=\"/web/flot/jquery.flot.js\"></script>\n"); sb.append("</head>\n"); // BEGIN BODY OPENING sb.append("\n<body>\n"); sb.append("<div id='content-wrapper'>\n"); sb.append("<div id='content'>\n"); sb.append("<div id='header'>"); if (!bannerText.isEmpty()) { sb.append("<div id='banner' style='color:") .append(bannerColor) .append(";background:") .append(bannerBackground) .append("'>") .append(bannerText) .append("</div>\n"); } sb.append("<div id='headertitle'>"); sb.append("<h1>").append(getTitle(req)).append("</h1></div>\n"); sb.append("<div id='subheader'>Instance Name: ") .append(cachedInstanceName) .append(" Version: ") .append(Constants.VERSION) .append("\n"); sb.append("<br><span class='smalltext'>Instance ID: ") .append(HdfsZooInstance.getInstance().getInstanceID()) .append("</span>\n"); sb.append("<br><span class='smalltext'>") .append(new Date().toString().replace(" ", " ")) .append("</span>"); sb.append("</div>\n"); // end <div id='subheader'> sb.append("</div>\n"); // end <div id='header'> // BEGIN LEFT SIDE sb.append("<div id='nav'>\n"); sb.append("<span id='nav-title'><a href='/'>Overview</a></span><br />\n"); sb.append("<hr />\n"); sb.append("<a href='/master'>Master Server</a><br />\n"); sb.append("<a href='/tservers'>Tablet Servers</a><br />\n"); sb.append("<a href='/loggers'>Logger Servers</a><br />\n"); sb.append("<a href='/vis'>Server Activity</a><br />\n"); sb.append("<a href='/gc'>Garbage Collector</a><br />\n"); sb.append("<a href='/tables'>Tables</a><br />\n"); sb.append("<a href='/trace/summary?minutes=10'>Recent Traces</a><br />\n"); sb.append("<a href='/docs'>Documentation</a><br />\n"); int numLogs = LogService.getInstance().getEvents().size(); if (numLogs > 0) sb.append( "<span class='error'><a href='/log'>Recent Logs <span class='smalltext'>(" + numLogs + ")</a></span></span><br />\n"); int numProblems = Monitor.getProblemSummary().entrySet().size(); if (numProblems > 0) sb.append( "<span class='error'><a href='/problems'>Table Problems <span class='smalltext'>(" + numProblems + ")</a></span></span><br />\n"); sb.append("<hr />\n"); sb.append("<a href='/xml'>XML</a><hr />\n"); sb.append("<div class='smalltext'>[<a href='") .append("/op?action=refresh&value=") .append(refresh < 1 ? "5" : "-1"); sb.append("&redir=").append(currentPage(req)).append("'>"); sb.append(refresh < 1 ? "en" : "dis").append("able auto-refresh</a>]</div>\n"); sb.append("</div>\n"); // end <div id='nav'> sb.append("<div id='main'"); if (bannerText.isEmpty()) sb.append(" style='bottom:0'"); sb.append(">\n"); sb.append("<!-- BEGIN MAIN BODY CONTENT -->\n\n"); }
protected void pageStart(HttpServletRequest req, HttpServletResponse resp, StringBuilder sb) throws Exception { resp.setContentType(DEFAULT_CONTENT_TYPE); int refresh = -1; String refreshStr = getCookieValue(req, "page.refresh.rate"); if (refreshStr != null) { try { refresh = Integer.parseInt(BasicServlet.decode(refreshStr)); } catch (NumberFormatException e) { // ignore improperly formatted user cookie } } // BEGIN PAGE sb.append("<!--\n"); sb.append(" Licensed to the Apache Software Foundation (ASF) under one or more\n"); sb.append(" contributor license agreements. See the NOTICE file distributed with\n"); sb.append(" this work for additional information regarding copyright ownership.\n"); sb.append(" The ASF licenses this file to You under the Apache License, Version 2.0\n"); sb.append(" (the \"License\"); you may not use this file except in compliance with\n"); sb.append(" the License. You may obtain a copy of the License at\n"); sb.append("\n"); sb.append(" http://www.apache.org/licenses/LICENSE-2.0\n"); sb.append("\n"); sb.append(" Unless required by applicable law or agreed to in writing, software\n"); sb.append(" distributed under the License is distributed on an \"AS IS\" BASIS,\n"); sb.append(" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); sb.append(" See the License for the specific language governing permissions and\n"); sb.append(" limitations under the License.\n"); sb.append("-->\n"); sb.append("<html>\n"); // BEGIN HEADER sb.append("<head>\n"); sb.append("<title>") .append(getTitle(req)) .append(" - Accumulo ") .append(Constants.VERSION) .append("</title>\n"); if ((refresh > 0) && (req.getRequestURI().startsWith("/vis") == false) && (req.getRequestURI().startsWith("/shell") == false)) sb.append("<meta http-equiv='refresh' content='" + refresh + "' />\n"); sb.append("<meta http-equiv='Content-Type' content='") .append(DEFAULT_CONTENT_TYPE) .append("' />\n"); sb.append("<meta http-equiv='Content-Script-Type' content='text/javascript' />\n"); sb.append("<meta http-equiv='Content-Style-Type' content='text/css' />\n"); sb.append("<link rel='shortcut icon' type='image/jpg' href='/web/favicon.png' />\n"); sb.append("<link rel='stylesheet' type='text/css' href='/web/screen.css' media='screen' />\n"); sb.append("<script src='/web/functions.js' type='text/javascript'></script>\n"); sb.append( "<!--[if lte IE 8]><script language=\"javascript\" type=\"text/javascript\" src=\"/web/flot/excanvas.min.js\"></script><![endif]-->\n"); sb.append( "<script language=\"javascript\" type=\"text/javascript\" src=\"/web/flot/jquery.js\"></script>\n"); sb.append( "<script language=\"javascript\" type=\"text/javascript\" src=\"/web/flot/jquery.flot.js\"></script>\n"); sb.append("</head>\n"); // BEGIN BODY OPENING sb.append("\n<body ").append(getBodyAttributes()).append(">\n"); sb.append("<div id='content-wrapper'>\n"); sb.append("<div id='content'>\n"); sb.append("<div id='header'>"); if (!bannerText.isEmpty()) { sb.append("<div id='banner' style='color:") .append(bannerColor) .append(";background:") .append(bannerBackground) .append("'>") .append(bannerText) .append("</div>\n"); } sb.append("<div id='headertitle'>"); sb.append("<h1>").append(getTitle(req)).append("</h1></div>\n"); sb.append("<div id='subheader'>Instance Name: ") .append(Monitor.cachedInstanceName.get()) .append(" Version: ") .append(Constants.VERSION) .append("\n"); sb.append("<br><span class='smalltext'>Instance ID: ") .append(Monitor.getContext().getInstance().getInstanceID()) .append("</span>\n"); sb.append("<br><span class='smalltext'>") .append(new Date().toString().replace(" ", " ")) .append("</span>"); sb.append("</div>\n"); // end <div id='subheader'> sb.append("</div>\n"); // end <div id='header'> // BEGIN LEFT SIDE sb.append("<div id='nav'>\n"); sb.append("<span id='nav-title'><a href='/'>Overview</a></span><br />\n"); sb.append("<hr />\n"); sb.append("<a href='/master'>Master Server</a><br />\n"); sb.append("<a href='/tservers'>Tablet Servers</a><br />\n"); sb.append("<a href='/scans'>Active Scans</a><br />\n"); sb.append("<a href='/bulkImports'>Bulk Imports</a><br />\n"); sb.append("<a href='/vis'>Server Activity</a><br />\n"); sb.append("<a href='/gc'>Garbage Collector</a><br />\n"); sb.append("<a href='/tables'>Tables</a><br />\n"); sb.append("<a href='/trace/summary?minutes=10'>Recent Traces</a><br />\n"); sb.append("<a href='/replication'>Replication</a><br />\n"); List<DedupedLogEvent> dedupedLogEvents = LogService.getInstance().getEvents(); int numLogs = dedupedLogEvents.size(); boolean logsHaveError = false; for (DedupedLogEvent dedupedLogEvent : dedupedLogEvents) if (dedupedLogEvent.getEvent().getLevel().isGreaterOrEqual(Level.ERROR)) { logsHaveError = true; break; } if (numLogs > 0) sb.append( "<span class='" + (logsHaveError ? "error" : "warning") + "'><a href='/log'>Recent Logs <span class='smalltext'>(" + numLogs + ")</a></span></span><br />\n"); int numProblems = Monitor.getProblemSummary().entrySet().size(); if (numProblems > 0) sb.append( "<span class='error'><a href='/problems'>Table Problems <span class='smalltext'>(" + numProblems + ")</a></span></span><br />\n"); sb.append("<hr />\n"); sb.append("<a href='/xml'>XML</a><br />\n"); sb.append("<a href='/json'>JSON</a><hr />\n"); if (Monitor.isUsingSsl()) sb.append("<a href='/shell'>Shell</a><hr />\n"); sb.append("<div class='smalltext'>[<a href='") .append("/op?action=refresh&value=") .append(refresh < 1 ? "5" : "-1"); sb.append("&redir=").append(currentPage(req)).append("'>"); sb.append(refresh < 1 ? "en" : "dis").append("able auto-refresh</a>]</div>\n"); sb.append("</div>\n"); // end <div id='nav'> sb.append("<div id='main'"); if (bannerText.isEmpty()) sb.append(" style='bottom:0'"); sb.append(">\n"); sb.append("<!-- BEGIN MAIN BODY CONTENT -->\n\n"); }