Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BD0B410E5C for ; Mon, 13 Jan 2014 19:33:23 +0000 (UTC) Received: (qmail 40196 invoked by uid 500); 13 Jan 2014 18:19:24 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 33968 invoked by uid 500); 13 Jan 2014 18:04:02 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 30569 invoked by uid 99); 13 Jan 2014 17:58:27 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Jan 2014 17:58:27 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 00CC083120A; Mon, 13 Jan 2014 17:58:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Mon, 13 Jan 2014 17:58:34 -0000 Message-Id: In-Reply-To: <06296dcd478c461a84990338e6140b75@git.apache.org> References: <06296dcd478c461a84990338e6140b75@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [09/11] git commit: Merge branch '1.5.1-SNAPSHOT' into 1.6.0-SNAPSHOT Merge branch '1.5.1-SNAPSHOT' into 1.6.0-SNAPSHOT Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9a81ca2d Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9a81ca2d Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9a81ca2d Branch: refs/heads/master Commit: 9a81ca2d90e5a26cc5aedab8238b91eb42b7dc13 Parents: b54266a 0603edb Author: Josh Elser Authored: Mon Jan 13 12:46:34 2014 -0500 Committer: Josh Elser Committed: Mon Jan 13 12:46:34 2014 -0500 ---------------------------------------------------------------------- .../java/org/apache/accumulo/monitor/servlets/DefaultServlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/9a81ca2d/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/DefaultServlet.java ---------------------------------------------------------------------- diff --cc server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/DefaultServlet.java index 8feca31,0000000..f6dd461 mode 100644,000000..100644 --- a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/DefaultServlet.java +++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/DefaultServlet.java @@@ -1,331 -1,0 +1,331 @@@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.monitor.servlets; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.accumulo.core.conf.DefaultConfiguration; +import org.apache.accumulo.core.conf.Property; +import org.apache.accumulo.core.file.FileUtil; +import org.apache.accumulo.core.master.thrift.MasterMonitorInfo; +import org.apache.accumulo.core.util.CachedConfiguration; +import org.apache.accumulo.core.util.Duration; +import org.apache.accumulo.core.util.NumUtil; +import org.apache.accumulo.core.util.Pair; +import org.apache.accumulo.monitor.Monitor; +import org.apache.accumulo.monitor.ZooKeeperStatus; +import org.apache.accumulo.monitor.ZooKeeperStatus.ZooKeeperState; +import org.apache.accumulo.monitor.util.celltypes.NumberType; +import org.apache.accumulo.server.conf.ServerConfiguration; +import org.apache.accumulo.server.trace.TraceFileSystem; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.ContentSummary; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; + +public class DefaultServlet extends BasicServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected String getTitle(HttpServletRequest req) { + return req.getRequestURI().startsWith("/docs") ? "Documentation" : "Accumulo Overview"; + } + + private void getResource(HttpServletRequest req, HttpServletResponse resp) throws IOException { + try { + String path = req.getRequestURI(); + + if (path.endsWith(".jpg")) + resp.setContentType("image/jpeg"); + + if (path.endsWith(".html")) + resp.setContentType("text/html"); + + path = path.substring(1); + InputStream data = BasicServlet.class.getClassLoader().getResourceAsStream(path); + ServletOutputStream out = resp.getOutputStream(); + try { + if (data != null) { + byte[] buffer = new byte[1024]; + int n; + while ((n = data.read(buffer)) > 0) + out.write(buffer, 0, n); + } else { + out.write(("could not get resource " + path + "").getBytes()); + } + } finally { + if (data != null) + data.close(); + } + } catch (Throwable t) { + log.error(t, t); + throw new IOException(t); + } + } + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + if (req.getRequestURI().startsWith("/web")) + getResource(req, resp); + else if (req.getRequestURI().equals("/docs") || req.getRequestURI().equals("/docs/apidocs")) + super.doGet(req, resp); + else if (req.getRequestURI().equals("/docs/config.html")) + new DefaultConfiguration() { + + public void generate(HttpServletResponse resp) throws IOException { + generateDocumentation(new PrintStream(resp.getOutputStream())); + + } + }.generate(resp); + else if (req.getRequestURI().startsWith("/docs")) + getResource(req, resp); + else if (req.getRequestURI().startsWith("/monitor")) + resp.sendRedirect("/master"); + else if (req.getRequestURI().startsWith("/errors")) + resp.sendRedirect("/problems"); + else + super.doGet(req, resp); + } + + public static final int GRAPH_WIDTH = 450; + public static final int GRAPH_HEIGHT = 150; + + private static void plotData(StringBuilder sb, String title, @SuppressWarnings("rawtypes") List data, boolean points) { + plotData(sb, title, points, new ArrayList(), data); + } + + @SuppressWarnings("rawtypes") + private static void plotData(StringBuilder sb, String title, boolean points, List labels, List... series) { + sb.append("
"); + sb.append(title); + sb.append("
"); + sb.append("
"); + String id = "c" + title.hashCode(); + sb.append("
\n"); + + sb.append("\n"); + } + + /** + * Shows the current time zone (based on the current time) short name + */ + private static String getShortTZName() { + TimeZone tz = TimeZone.getDefault(); + return tz.getDisplayName(tz.inDaylightTime(new Date()), TimeZone.SHORT); + } + + /** + * Converts a unix timestamp in UTC to one that is relative to the local timezone + */ + private static Long utc2local(Long utcMillis) { + Calendar currentCalendar = Calendar.getInstance(); // default timezone + currentCalendar.setTimeInMillis(utcMillis + currentCalendar.getTimeZone().getOffset(utcMillis)); + return currentCalendar.getTime().getTime(); + } + + @Override + protected void pageBody(HttpServletRequest req, HttpServletResponse resp, StringBuilder sb) throws IOException { + if (req.getRequestURI().equals("/docs") || req.getRequestURI().equals("/docs/apidocs")) { + sb.append(""); + return; + } + + sb.append("\n"); + sb.append("\n"); + + sb.append("\n"); + + sb.append("\n"); + + sb.append("
\n"); + doAccumuloTable(sb); + sb.append("\n"); + doZooKeeperTable(sb); + sb.append("
\n"); + sb.append("
\n"); + + sb.append("

\n"); + + sb.append("\n"); + + sb.append("\n"); + + sb.append("\n"); + + sb.append("\n"); + + sb.append("\n"); + + sb.append("
\n"); + plotData(sb, "Ingest (Entries/s)", Monitor.getIngestRateOverTime(), false); + sb.append("\n"); + plotData(sb, "Scan (Entries/s)", false, Arrays.asList("Read", "Returned"), Monitor.getScanRateOverTime(), Monitor.getQueryRateOverTime()); + sb.append("
\n"); + plotData(sb, "Ingest (MB/s)", Monitor.getIngestByteRateOverTime(), false); + sb.append("\n"); + plotData(sb, "Scan (MB/s)", Monitor.getQueryByteRateOverTime(), false); + sb.append("
\n"); + plotData(sb, "Load Average", Monitor.getLoadOverTime(), false); + sb.append("\n"); + plotData(sb, "Seeks", Monitor.getLookupsOverTime(), false); + sb.append("
\n"); + plotData(sb, "Minor Compactions", Monitor.getMinorCompactionsOverTime(), false); + sb.append("\n"); + plotData(sb, "Major Compactions", Monitor.getMajorCompactionsOverTime(), false); + sb.append("
\n"); + plotData(sb, "Index Cache Hit Rate", Monitor.getIndexCacheHitRateOverTime(), true); + sb.append("\n"); + plotData(sb, "Data Cache Hit Rate", Monitor.getDataCacheHitRateOverTime(), true); + sb.append("
\n"); + } + + private void doAccumuloTable(StringBuilder sb) throws IOException { + // Accumulo + Configuration conf = CachedConfiguration.getInstance(); + FileSystem fs = TraceFileSystem.wrap(FileUtil.getFileSystem(conf, ServerConfiguration.getSiteConfiguration())); + MasterMonitorInfo info = Monitor.getMmi(); + sb.append("\n"); + sb.append("\n"); + if (info == null) { + sb.append("\n"); + } else { + String consumed = "Unknown"; + String diskUsed = "Unknown"; + try { + Path path = new Path(Monitor.getSystemConfiguration().get(Property.INSTANCE_DFS_DIR)); + log.debug("Reading the content summary for " + path); + try { + ContentSummary acu = fs.getContentSummary(path); ++ diskUsed = bytes(acu.getSpaceConsumed()); + ContentSummary rootSummary = fs.getContentSummary(new Path("/")); + consumed = String.format("%.2f%%", acu.getSpaceConsumed() * 100. / rootSummary.getSpaceConsumed()); - diskUsed = bytes(acu.getSpaceConsumed()); + } catch (Exception ex) { + log.trace("Unable to get disk usage information from hdfs", ex); + } + + boolean highlight = false; + tableRow(sb, (highlight = !highlight), "Disk Used", diskUsed); + if (fs.getUsed() != 0) + tableRow(sb, (highlight = !highlight), "% of Used DFS", consumed); + tableRow(sb, (highlight = !highlight), "Tables", NumberType.commas(Monitor.getTotalTables())); + tableRow(sb, (highlight = !highlight), "Tablet Servers", NumberType.commas(info.tServerInfo.size(), 1, Long.MAX_VALUE)); + tableRow(sb, (highlight = !highlight), "Dead Tablet Servers", NumberType.commas(info.deadTabletServers.size(), 0, 0)); + tableRow(sb, (highlight = !highlight), "Tablets", NumberType.commas(Monitor.getTotalTabletCount(), 1, Long.MAX_VALUE)); + tableRow(sb, (highlight = !highlight), "Entries", NumberType.commas(Monitor.getTotalEntries())); + tableRow(sb, (highlight = !highlight), "Lookups", NumberType.commas(Monitor.getTotalLookups())); + tableRow(sb, (highlight = !highlight), "Uptime", Duration.format(System.currentTimeMillis() - Monitor.getStartTime())); + } catch (Exception e) { + log.debug(e, e); + } + } + sb.append("
Accumulo Master
Master is Down
\n"); + } + + private void doZooKeeperTable(StringBuilder sb) throws IOException { + // Zookeepers + sb.append("\n"); + sb.append("\n"); + sb.append("\n"); + + boolean highlight = false; + for (ZooKeeperState k : ZooKeeperStatus.getZooKeeperStatus()) { + if (k.clients >= 0) { + tableRow(sb, (highlight = !highlight), k.keeper, k.mode, k.clients); + } else { + tableRow(sb, false, k.keeper, "Down", ""); + } + } + sb.append("
Zookeeper
ServerModeClients
\n"); + } + + private static String bytes(long big) { + return NumUtil.bigNumberForSize(big); + } + + public static void tableRow(StringBuilder sb, boolean highlight, Object... cells) { + sb.append(highlight ? "" : ""); + for (int i = 0; i < cells.length; ++i) { + Object cell = cells[i]; + String cellValue = cell == null ? "" : String.valueOf(cell).trim(); + sb.append("").append(cellValue.isEmpty() ? "-" : cellValue).append(""); + } + sb.append("\n"); + } +}