- Move oldconsole rendering from Router to OldConsoleHelper

This commit is contained in:
zzz
2012-03-24 23:04:05 +00:00
parent bdfca07626
commit ed13424913
3 changed files with 39 additions and 284 deletions

View File

@ -40,6 +40,7 @@
<dependset>
<srcfilelist dir="." files="../../../router/java/build/obj/net/i2p/router/RouterVersion.class" />
<targetfilelist dir="." files="build/obj/net/i2p/router/web/NewsFetcher.class" />
<targetfilelist dir="." files="build/obj/net/i2p/router/web/OldConsoleHelper.class" />
<targetfilelist dir="." files="build/obj/net/i2p/router/web/PluginStarter.class" />
<targetfilelist dir="." files="build/obj/net/i2p/router/web/SummaryHelper.class" />
<targetfilelist dir="." files="build/obj/net/i2p/router/web/UpdateHandler.class" />

View File

@ -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 "<b>Error displaying the console.</b>";
}
}
/**
* 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("<b>Router: </b> ").append(h.toBase64()).append("<br>\n");
buf.append("<b>As of: </b> ").append(new Date(_context.clock().now())).append("<br>\n");
buf.append("<b>RouterUptime: </b> " ).append(DataHelper.formatDuration(_context.router().getUptime())).append(" <br>\n");
buf.append("<b>Started on: </b> ").append(new Date(_context.router().getWhenStarted())).append("<br>\n");
buf.append("<b>Clock offset: </b> ").append(_context.clock().getOffset()).append("ms (OS time: ").append(new Date(_context.clock().now() - _context.clock().getOffset())).append(")<br>\n");
buf.append("<b>RouterVersion:</b> ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("<br>\n");
long tot = Runtime.getRuntime().totalMemory()/1024;
long free = Runtime.getRuntime().freeMemory()/1024;
buf.append("<b>Memory:</b> In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB <br>\n");
out.write(buf.toString());
out.flush();
}
}

View File

@ -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("<h1>Router console</h1>\n" +
"<i><a href=\"/oldconsole.jsp\">console</a> | <a href=\"/oldstats.jsp\">stats</a></i><br>\n" +
"<form action=\"/oldconsole.jsp\">" +
"<select name=\"go\" onChange='location.href=this.value'>" +
"<option value=\"/oldconsole.jsp#bandwidth\">Bandwidth</option>\n" +
"<option value=\"/oldconsole.jsp#clients\">Clients</option>\n" +
"<option value=\"/oldconsole.jsp#transports\">Transports</option>\n" +
"<option value=\"/oldconsole.jsp#profiles\">Peer Profiles</option>\n" +
"<option value=\"/oldconsole.jsp#tunnels\">Tunnels</option>\n" +
"<option value=\"/oldconsole.jsp#jobs\">Jobs</option>\n" +
"<option value=\"/oldconsole.jsp#shitlist\">Shitlist</option>\n" +
"<option value=\"/oldconsole.jsp#pending\">Pending messages</option>\n" +
"<option value=\"/oldconsole.jsp#netdb\">Network Database</option>\n" +
"<option value=\"/oldconsole.jsp#logs\">Log messages</option>\n" +
"</select> <input type=\"submit\" value=\"GO\" /> </form>" +
"<hr>\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("<b>Router: </b> ").append(_routerInfo.getIdentity().getHash().toBase64()).append("<br>\n");
buf.append("<b>As of: </b> ").append(new Date(_context.clock().now())).append("<br>\n");
buf.append("<b>RouterUptime: </b> " ).append(DataHelper.formatDuration(getUptime())).append(" <br>\n");
buf.append("<b>Started on: </b> ").append(new Date(getWhenStarted())).append("<br>\n");
buf.append("<b>Clock offset: </b> ").append(_context.clock().getOffset()).append("ms (OS time: ").append(new Date(_context.clock().now() - _context.clock().getOffset())).append(")<br>\n");
buf.append("<b>RouterVersion:</b> ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("<br>\n");
long tot = Runtime.getRuntime().totalMemory()/1024;
long free = Runtime.getRuntime().freeMemory()/1024;
buf.append("<b>Memory:</b> In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB <br>\n");
if (_higherVersionSeen)
buf.append("<b><font color=\"red\">HIGHER VERSION SEEN</font><b> - please <a href=\"http://www.i2p.net/\">check</a> to see if there is a new release out<br>\n");
/*********
buf.append("<hr><a name=\"bandwidth\"> </a><h2>Bandwidth</h2>\n");
long sent = _context.bandwidthLimiter().getTotalAllocatedOutboundBytes();
long received = _context.bandwidthLimiter().getTotalAllocatedInboundBytes();
buf.append("<ul>");
buf.append("<li> ").append(sent).append(" bytes sent, ");
buf.append(received).append(" bytes received</li>");
long notSent = _context.bandwidthLimiter().getTotalWastedOutboundBytes();
long notReceived = _context.bandwidthLimiter().getTotalWastedInboundBytes();
buf.append("<li> ").append(notSent).append(" bytes outbound bytes unused, ");
buf.append(notReceived).append(" bytes inbound bytes unused</li>");
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("<li>Lifetime rate: ");
buf.append(fmt.format(sendKBps)).append("KBps sent ");
buf.append(fmt.format(receivedKBps)).append("KBps received");
buf.append("</li>");
}
if ( (notSent > 0) && (notReceived > 0) ) {
double notSendKBps = notSent / (lifetime*1024.0);
double notReceivedKBps = notReceived / (lifetime*1024.0);
buf.append("<li>Lifetime unused rate: ");
buf.append(fmt.format(notSendKBps)).append("KBps outbound unused ");
buf.append(fmt.format(notReceivedKBps)).append("KBps inbound unused");
buf.append("</li>");
}
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("<li>");
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("</li><li>");
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("</li>");
}
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("<li>");
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("</li><li>");
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("</li>");
}
buf.append("</ul>\n");
buf.append("<i>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]</i>");
buf.append("\n");
out.write(buf.toString());
_context.bandwidthLimiter().renderStatusHTML(out);
out.write("<hr><a name=\"clients\"> </a>\n");
_context.clientManager().renderStatusHTML(out);
out.write("\n<hr><a name=\"transports\"> </a>\n");
_context.commSystem().renderStatusHTML(out);
out.write("\n<hr><a name=\"profiles\"> </a>\n");
_context.peerManager().renderStatusHTML(out);
out.write("\n<hr><a name=\"tunnels\"> </a>\n");
_context.tunnelManager().renderStatusHTML(out);
out.write("\n<hr><a name=\"jobs\"> </a>\n");
_context.jobQueue().renderStatusHTML(out);
out.write("\n<hr><a name=\"shitlist\"> </a>\n");
_context.shitlist().renderStatusHTML(out);
out.write("\n<hr><a name=\"pending\"> </a>\n");
_context.messageRegistry().renderStatusHTML(out);
out.write("\n<hr><a name=\"netdb\"> </a>\n");
_context.netDb().renderLeaseSetHTML(out);
_context.netDb().renderStatusHTML(out);
buf.setLength(0);
buf.append("\n<hr><a name=\"logs\"> </a>\n");
List msgs = _context.logManager().getBuffer().getMostRecentMessages();
buf.append("\n<h2>Most recent console messages:</h2><table>\n");
for (Iterator iter = msgs.iterator(); iter.hasNext(); ) {
String msg = (String)iter.next();
buf.append("<tr><td align=\"left\"><pre>");
appendLogMessage(buf, msg);
buf.append("</pre></td></tr>\n");
}
buf.append("</table>\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;