From ed13424913a1395ba1ebbb866ae52862f3f9f0ce Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 24 Mar 2012 23:04:05 +0000 Subject: [PATCH] - Move oldconsole rendering from Router to OldConsoleHelper --- apps/routerconsole/java/build.xml | 1 + .../net/i2p/router/web/OldConsoleHelper.java | 41 ++- router/java/src/net/i2p/router/Router.java | 281 ------------------ 3 files changed, 39 insertions(+), 284 deletions(-) diff --git a/apps/routerconsole/java/build.xml b/apps/routerconsole/java/build.xml index 9eb388d81..2ced130bb 100644 --- a/apps/routerconsole/java/build.xml +++ b/apps/routerconsole/java/build.xml @@ -40,6 +40,7 @@ + diff --git a/apps/routerconsole/java/src/net/i2p/router/web/OldConsoleHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/OldConsoleHelper.java index 100d7140a..8ddf7b261 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/OldConsoleHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/OldConsoleHelper.java @@ -3,6 +3,13 @@ package net.i2p.router.web; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Date; + +import net.i2p.CoreVersion; +import net.i2p.data.DataHelper; +import net.i2p.data.Hash; +import net.i2p.router.RouterVersion; public class OldConsoleHelper extends HelperBase { @@ -17,11 +24,11 @@ public class OldConsoleHelper extends HelperBase { public String getConsole() { try { if (_out != null) { - _context.router().renderStatusHTML(_out); + renderStatusHTML(_out); return ""; } else { - ByteArrayOutputStream baos = new ByteArrayOutputStream(128*1024); - _context.router().renderStatusHTML(new OutputStreamWriter(baos)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(2*1024); + renderStatusHTML(new OutputStreamWriter(baos)); return baos.toString(); } } catch (IOException ioe) { @@ -44,4 +51,32 @@ public class OldConsoleHelper extends HelperBase { return "Error displaying the console."; } } + + /** + * this is for oldconsole.jsp, pretty much unused except as a way to get memory info, + * so let's comment out the rest, it is available elsewhere, and we don't really + * want to spend a minute rendering a multi-megabyte page in memory. + * + * @since 0.9 moved from Router.java + */ + private void renderStatusHTML(Writer out) throws IOException { + StringBuilder buf = new StringBuilder(4*1024); + + // Please don't change the text or formatting, tino matches it in his scripts + Hash h = _context.routerHash(); + if (h != null) + buf.append("Router: ").append(h.toBase64()).append("
\n"); + buf.append("As of: ").append(new Date(_context.clock().now())).append("
\n"); + buf.append("RouterUptime: " ).append(DataHelper.formatDuration(_context.router().getUptime())).append("
\n"); + buf.append("Started on: ").append(new Date(_context.router().getWhenStarted())).append("
\n"); + buf.append("Clock offset: ").append(_context.clock().getOffset()).append("ms (OS time: ").append(new Date(_context.clock().now() - _context.clock().getOffset())).append(")
\n"); + buf.append("RouterVersion: ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("
\n"); + long tot = Runtime.getRuntime().totalMemory()/1024; + long free = Runtime.getRuntime().freeMemory()/1024; + buf.append("Memory: In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB
\n"); + + out.write(buf.toString()); + out.flush(); + } + } diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 24560b3af..fa0f2ba38 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -727,287 +727,6 @@ public class Router implements RouterClock.ClockShiftListener { //_context.inNetMessagePool().registerHandlerJobBuilder(TunnelMessage.MESSAGE_TYPE, new TunnelMessageHandler(_context)); } - /** - * this is for oldconsole.jsp, pretty much unused except as a way to get memory info, - * so let's comment out the rest, it is available elsewhere, and we don't really - * want to spend a minute rendering a multi-megabyte page in memory. - */ - public void renderStatusHTML(Writer out) throws IOException { -/**************** - out.write("

Router console

\n" + - "console | stats
\n" + - "
" + - "
" + - "
\n"); -**************/ - - StringBuilder buf = new StringBuilder(4*1024); - - // Please don't change the text or formatting, tino matches it in his scripts - if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) ) - buf.append("Router: ").append(_routerInfo.getIdentity().getHash().toBase64()).append("
\n"); - buf.append("As of: ").append(new Date(_context.clock().now())).append("
\n"); - buf.append("RouterUptime: " ).append(DataHelper.formatDuration(getUptime())).append("
\n"); - buf.append("Started on: ").append(new Date(getWhenStarted())).append("
\n"); - buf.append("Clock offset: ").append(_context.clock().getOffset()).append("ms (OS time: ").append(new Date(_context.clock().now() - _context.clock().getOffset())).append(")
\n"); - buf.append("RouterVersion: ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("
\n"); - long tot = Runtime.getRuntime().totalMemory()/1024; - long free = Runtime.getRuntime().freeMemory()/1024; - buf.append("Memory: In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB
\n"); - if (_higherVersionSeen) - buf.append("HIGHER VERSION SEEN - please check to see if there is a new release out
\n"); - -/********* - buf.append("

Bandwidth

\n"); - long sent = _context.bandwidthLimiter().getTotalAllocatedOutboundBytes(); - long received = _context.bandwidthLimiter().getTotalAllocatedInboundBytes(); - buf.append("
    "); - - buf.append("
  • ").append(sent).append(" bytes sent, "); - buf.append(received).append(" bytes received
  • "); - - long notSent = _context.bandwidthLimiter().getTotalWastedOutboundBytes(); - long notReceived = _context.bandwidthLimiter().getTotalWastedInboundBytes(); - - buf.append("
  • ").append(notSent).append(" bytes outbound bytes unused, "); - buf.append(notReceived).append(" bytes inbound bytes unused
  • "); - - DecimalFormat fmt = new DecimalFormat("##0.00"); - - // we use the unadjusted time, since thats what getWhenStarted is based off - long lifetime = _context.clock().now()-_context.clock().getOffset() - getWhenStarted(); - lifetime /= 1000; - if ( (sent > 0) && (received > 0) ) { - double sendKBps = sent / (lifetime*1024.0); - double receivedKBps = received / (lifetime*1024.0); - buf.append("
  • Lifetime rate: "); - buf.append(fmt.format(sendKBps)).append("KBps sent "); - buf.append(fmt.format(receivedKBps)).append("KBps received"); - buf.append("
  • "); - } - if ( (notSent > 0) && (notReceived > 0) ) { - double notSendKBps = notSent / (lifetime*1024.0); - double notReceivedKBps = notReceived / (lifetime*1024.0); - buf.append("
  • Lifetime unused rate: "); - buf.append(fmt.format(notSendKBps)).append("KBps outbound unused "); - buf.append(fmt.format(notReceivedKBps)).append("KBps inbound unused"); - buf.append("
  • "); - } - - RateStat sendRate = _context.statManager().getRate("transport.sendMessageSize"); - for (int i = 0; i < sendRate.getPeriods().length; i++) { - Rate rate = sendRate.getRate(sendRate.getPeriods()[i]); - double bytes = rate.getLastTotalValue(); - long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime(); - if (ms <= 0) { - bytes = 0; - ms = 1; - } - buf.append("
  • "); - buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous send avg: "); - double bps = bytes*1000.0d/ms; - if (bps > 2048) { - bps /= 1024.0d; - buf.append(fmt.format(bps)).append(" KBps"); - } else { - buf.append(fmt.format(bps)).append(" Bps"); - } - buf.append(" over ").append((long)bytes).append(" bytes"); - buf.append("
  • "); - buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period send avg: "); - bps = bytes*1000.0d/(rate.getPeriod()); - if (bps > 2048) { - bps /= 1024.0d; - buf.append(fmt.format(bps)).append(" KBps"); - } else { - buf.append(fmt.format(bps)).append(" Bps"); - } - buf.append(" over ").append((long)bytes).append(" bytes"); - buf.append("
  • "); - } - - RateStat receiveRate = _context.statManager().getRate("transport.receiveMessageSize"); - for (int i = 0; i < receiveRate.getPeriods().length; i++) { - Rate rate = receiveRate.getRate(receiveRate.getPeriods()[i]); - double bytes = rate.getLastTotalValue(); - long ms = rate.getLastTotalEventTime(); - if (ms <= 0) { - bytes = 0; - ms = 1; - } - buf.append("
  • "); - buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous receive avg: "); - double bps = bytes*1000.0d/ms; - if (bps > 2048) { - bps /= 1024.0d; - buf.append(fmt.format(bps)).append(" KBps "); - } else { - buf.append(fmt.format(bps)).append(" Bps "); - } - buf.append(" over ").append((long)bytes).append(" bytes"); - buf.append("
  • "); - buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period receive avg: "); - bps = bytes*1000.0d/(rate.getPeriod()); - if (bps > 2048) { - bps /= 1024.0d; - buf.append(fmt.format(bps)).append(" KBps"); - } else { - buf.append(fmt.format(bps)).append(" Bps"); - } - buf.append(" over ").append((long)bytes).append(" bytes"); - buf.append("
  • "); - } - - buf.append("
\n"); - buf.append("Instantaneous averages count how fast the transfers go when we're trying to transfer data, "); - buf.append("while period averages count how fast the transfers go across the entire period, even when we're not "); - buf.append("trying to transfer data. Lifetime averages count how many elephants there are on the moon [like anyone reads this text]"); - buf.append("\n"); - - out.write(buf.toString()); - - _context.bandwidthLimiter().renderStatusHTML(out); - - out.write("
\n"); - - _context.clientManager().renderStatusHTML(out); - - out.write("\n
\n"); - - _context.commSystem().renderStatusHTML(out); - - out.write("\n
\n"); - - _context.peerManager().renderStatusHTML(out); - - out.write("\n
\n"); - - _context.tunnelManager().renderStatusHTML(out); - - out.write("\n
\n"); - - _context.jobQueue().renderStatusHTML(out); - - out.write("\n
\n"); - - _context.shitlist().renderStatusHTML(out); - - out.write("\n
\n"); - - _context.messageRegistry().renderStatusHTML(out); - - out.write("\n
\n"); - - _context.netDb().renderLeaseSetHTML(out); - _context.netDb().renderStatusHTML(out); - - buf.setLength(0); - buf.append("\n
\n"); - List msgs = _context.logManager().getBuffer().getMostRecentMessages(); - buf.append("\n

Most recent console messages:

\n"); - for (Iterator iter = msgs.iterator(); iter.hasNext(); ) { - String msg = (String)iter.next(); - buf.append("\n"); - } - buf.append("
");
-            appendLogMessage(buf, msg);
-            buf.append("
\n"); -***********/ - out.write(buf.toString()); - out.flush(); - } - - //private static int MAX_MSG_LENGTH = 120; - private static final void appendLogMessage(StringBuilder buf, String msg) { - // disable this code for the moment because i think it - // looks ugly (on the router console) - //if (true) { - buf.append(msg); - return; - //} -/****** - if (msg.length() < MAX_MSG_LENGTH) { - buf.append(msg); - return; - } - int newline = msg.indexOf('\n'); - int len = msg.length(); - while ( (msg != null) && (len > 0) ) { - if (newline < 0) { - // last line, trim if necessary - if (len > MAX_MSG_LENGTH) - msg = msg.substring(len-MAX_MSG_LENGTH); - buf.append(msg); - return; - } else if (newline >= MAX_MSG_LENGTH) { - // not the last line, but too long. - // trim the first few chars - String cur = msg.substring(newline-MAX_MSG_LENGTH, newline).trim(); - msg = msg.substring(newline+1); - if (cur.length() > 0) - buf.append(cur).append('\n'); - } else { - // newline <= max_msg_length, so its not the last, - // and not too long - String cur = msg.substring(0, newline).trim(); - msg = msg.substring(newline+1); - if (cur.length() > 0) - buf.append(cur).append('\n'); - } - newline = msg.indexOf('\n'); - len = msg.length(); - } -******/ - } - - /** main-ish method for testing appendLogMessage */ -/****** - private static final void testAppendLog() { - StringBuilder buf = new StringBuilder(1024); - Router.appendLogMessage(buf, "hi\nhow are you\nh0h0h0"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, "\nfine thanks\nh0h0h0"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, "liar\nblah blah\n"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, "\n"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, ""); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, ".........10........20........30........40........50........6"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, ".........10........\n20........30........40........50........6"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, ".........10........20\n........30........40........50........6"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, ".........10.......\n.20........30........40........50........6"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - Router.appendLogMessage(buf, "\n.........10........20........30........40........50........6"); - System.out.println("line: [" + buf.toString() + "]"); - buf.setLength(0); - } -******/ - public static final int EXIT_GRACEFUL = 2; public static final int EXIT_HARD = 3; public static final int EXIT_OOM = 10;