@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { StringBuilder sb = new StringBuilder(); try { Monitor.fetchData(); bannerText = sanitize(Monitor.getContext().getConfiguration().get(Property.MONITOR_BANNER_TEXT)); bannerColor = Monitor.getContext() .getConfiguration() .get(Property.MONITOR_BANNER_COLOR) .replace("'", "'"); bannerBackground = Monitor.getContext() .getConfiguration() .get(Property.MONITOR_BANNER_BACKGROUND) .replace("'", "'"); pageStart(req, resp, sb); pageBody(req, resp, sb); pageEnd(req, resp, sb); } catch (Throwable t) { log.error("Error building page " + req.getRequestURI(), t); sb.append("\n<pre>\n"); StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); sb.append(sanitize(sw.getBuffer().toString())); sb.append("</pre>\n"); } finally { resp.getWriter().print(sb); resp.getWriter().flush(); } }
public EmbeddedWebServer(String host, int port) { server = new Server(); handler = new ContextHandlerCollection(); root = new Context(handler, "/", new SessionHandler(), null, null, null); if (EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE)) || EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS)) || EMPTY.equals(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE)) || EMPTY.equals( Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS))) { sock = new SocketConnector(); usingSsl = false; } else { sock = new SslSocketConnector(); ((SslSocketConnector) sock) .setKeystore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE)); ((SslSocketConnector) sock) .setKeyPassword(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS)); ((SslSocketConnector) sock) .setTruststore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE)); ((SslSocketConnector) sock) .setTrustPassword( Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS)); usingSsl = true; } sock.setHost(host); sock.setPort(port); }
public static void main(String[] args) throws Exception { SecurityUtil.serverLogin(ServerConfiguration.getSiteConfiguration()); VolumeManager fs = VolumeManagerImpl.get(); ServerOpts opts = new ServerOpts(); opts.parseArgs("monitor", args); String hostname = opts.getAddress(); instance = HdfsZooInstance.getInstance(); config = new ServerConfiguration(instance); Accumulo.init(fs, config, "monitor"); Monitor monitor = new Monitor(); Accumulo.enableTracing(hostname, "monitor"); monitor.run(hostname); }
protected Scanner getScanner(StringBuilder sb) throws AccumuloException, AccumuloSecurityException { AccumuloConfiguration conf = Monitor.getSystemConfiguration(); String principal = conf.get(Property.TRACE_USER); AuthenticationToken at; Map<String, String> loginMap = conf.getAllPropertiesWithPrefix(Property.TRACE_TOKEN_PROPERTY_PREFIX); if (loginMap.isEmpty()) { Property p = Property.TRACE_PASSWORD; at = new PasswordToken(conf.get(p).getBytes(StandardCharsets.UTF_8)); } else { Properties props = new Properties(); int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length(); for (Entry<String, String> entry : loginMap.entrySet()) { props.put(entry.getKey().substring(prefixLength), entry.getValue()); } AuthenticationToken token = Property.createInstanceFromPropertyName( conf, Property.TRACE_TOKEN_TYPE, AuthenticationToken.class, new PasswordToken()); token.init(props); at = token; } String table = conf.get(Property.TRACE_TABLE); try { Connector conn = HdfsZooInstance.getInstance().getConnector(principal, at); if (!conn.tableOperations().exists(table)) { return new NullScanner(); } Scanner scanner = conn.createScanner(table, conn.securityOperations().getUserAuthorizations(principal)); return scanner; } catch (AccumuloSecurityException ex) { sb.append( "<h2>Unable to read trace table: check trace username and password configuration.</h2>\n"); return null; } catch (TableNotFoundException ex) { return new NullScanner(); } }
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; 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"); }