Changeset ed134249


Ignore:
Timestamp:
Mar 24, 2012 11:04:05 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3e889d2
Parents:
bdfca07
Message:
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/build.xml

    rbdfca07 red134249  
    4141             <srcfilelist dir="." files="../../../router/java/build/obj/net/i2p/router/RouterVersion.class" />
    4242             <targetfilelist dir="." files="build/obj/net/i2p/router/web/NewsFetcher.class" />
     43             <targetfilelist dir="." files="build/obj/net/i2p/router/web/OldConsoleHelper.class" />
    4344             <targetfilelist dir="." files="build/obj/net/i2p/router/web/PluginStarter.class" />
    4445             <targetfilelist dir="." files="build/obj/net/i2p/router/web/SummaryHelper.class" />
  • apps/routerconsole/java/src/net/i2p/router/web/OldConsoleHelper.java

    rbdfca07 red134249  
    44import java.io.IOException;
    55import java.io.OutputStreamWriter;
     6import java.io.Writer;
     7import java.util.Date;
     8
     9import net.i2p.CoreVersion;
     10import net.i2p.data.DataHelper;
     11import net.i2p.data.Hash;
     12import net.i2p.router.RouterVersion;
    613
    714
     
    1825        try {
    1926            if (_out != null) {
    20                 _context.router().renderStatusHTML(_out);
     27                renderStatusHTML(_out);
    2128                return "";
    2229            } else {
    23                 ByteArrayOutputStream baos = new ByteArrayOutputStream(128*1024);
    24                 _context.router().renderStatusHTML(new OutputStreamWriter(baos));
     30                ByteArrayOutputStream baos = new ByteArrayOutputStream(2*1024);
     31                renderStatusHTML(new OutputStreamWriter(baos));
    2532                return baos.toString();
    2633            }
     
    4552        }
    4653    }
     54
     55    /**
     56     *  this is for oldconsole.jsp, pretty much unused except as a way to get memory info,
     57     *  so let's comment out the rest, it is available elsewhere, and we don't really
     58     *  want to spend a minute rendering a multi-megabyte page in memory.
     59     *
     60     *  @since 0.9 moved from Router.java
     61     */
     62    private void renderStatusHTML(Writer out) throws IOException {
     63        StringBuilder buf = new StringBuilder(4*1024);
     64       
     65        // Please don't change the text or formatting, tino matches it in his scripts
     66        Hash h = _context.routerHash();
     67        if (h != null)
     68            buf.append("<b>Router: </b> ").append(h.toBase64()).append("<br>\n");
     69        buf.append("<b>As of: </b> ").append(new Date(_context.clock().now())).append("<br>\n");
     70        buf.append("<b>RouterUptime: </b> " ).append(DataHelper.formatDuration(_context.router().getUptime())).append(" <br>\n");
     71        buf.append("<b>Started on: </b> ").append(new Date(_context.router().getWhenStarted())).append("<br>\n");
     72        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");
     73        buf.append("<b>RouterVersion:</b> ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("<br>\n");
     74        long tot = Runtime.getRuntime().totalMemory()/1024;
     75        long free = Runtime.getRuntime().freeMemory()/1024;
     76        buf.append("<b>Memory:</b> In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB <br>\n");
     77
     78        out.write(buf.toString());
     79        out.flush();
     80    }
     81   
    4782}
  • router/java/src/net/i2p/router/Router.java

    rbdfca07 red134249  
    728728    }
    729729   
    730     /**
    731      *  this is for oldconsole.jsp, pretty much unused except as a way to get memory info,
    732      *  so let's comment out the rest, it is available elsewhere, and we don't really
    733      *  want to spend a minute rendering a multi-megabyte page in memory.
    734      */
    735     public void renderStatusHTML(Writer out) throws IOException {
    736 /****************
    737         out.write("<h1>Router console</h1>\n" +
    738                    "<i><a href=\"/oldconsole.jsp\">console</a> | <a href=\"/oldstats.jsp\">stats</a></i><br>\n" +
    739                    "<form action=\"/oldconsole.jsp\">" +
    740                    "<select name=\"go\" onChange='location.href=this.value'>" +
    741                    "<option value=\"/oldconsole.jsp#bandwidth\">Bandwidth</option>\n" +
    742                    "<option value=\"/oldconsole.jsp#clients\">Clients</option>\n" +
    743                    "<option value=\"/oldconsole.jsp#transports\">Transports</option>\n" +
    744                    "<option value=\"/oldconsole.jsp#profiles\">Peer Profiles</option>\n" +
    745                    "<option value=\"/oldconsole.jsp#tunnels\">Tunnels</option>\n" +
    746                    "<option value=\"/oldconsole.jsp#jobs\">Jobs</option>\n" +
    747                    "<option value=\"/oldconsole.jsp#shitlist\">Shitlist</option>\n" +
    748                    "<option value=\"/oldconsole.jsp#pending\">Pending messages</option>\n" +
    749                    "<option value=\"/oldconsole.jsp#netdb\">Network Database</option>\n" +
    750                    "<option value=\"/oldconsole.jsp#logs\">Log messages</option>\n" +
    751                    "</select> <input type=\"submit\" value=\"GO\" /> </form>" +
    752                    "<hr>\n");
    753 **************/
    754 
    755         StringBuilder buf = new StringBuilder(4*1024);
    756        
    757         // Please don't change the text or formatting, tino matches it in his scripts
    758         if ( (_routerInfo != null) && (_routerInfo.getIdentity() != null) )
    759             buf.append("<b>Router: </b> ").append(_routerInfo.getIdentity().getHash().toBase64()).append("<br>\n");
    760         buf.append("<b>As of: </b> ").append(new Date(_context.clock().now())).append("<br>\n");
    761         buf.append("<b>RouterUptime: </b> " ).append(DataHelper.formatDuration(getUptime())).append(" <br>\n");
    762         buf.append("<b>Started on: </b> ").append(new Date(getWhenStarted())).append("<br>\n");
    763         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");
    764         buf.append("<b>RouterVersion:</b> ").append(RouterVersion.FULL_VERSION).append(" / SDK: ").append(CoreVersion.VERSION).append("<br>\n");
    765         long tot = Runtime.getRuntime().totalMemory()/1024;
    766         long free = Runtime.getRuntime().freeMemory()/1024;
    767         buf.append("<b>Memory:</b> In use: ").append((tot-free)).append("KB Free: ").append(free).append("KB <br>\n");
    768         if (_higherVersionSeen)
    769             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");
    770 
    771 /*********
    772         buf.append("<hr><a name=\"bandwidth\"> </a><h2>Bandwidth</h2>\n");
    773         long sent = _context.bandwidthLimiter().getTotalAllocatedOutboundBytes();
    774         long received = _context.bandwidthLimiter().getTotalAllocatedInboundBytes();
    775         buf.append("<ul>");
    776 
    777         buf.append("<li> ").append(sent).append(" bytes sent, ");
    778         buf.append(received).append(" bytes received</li>");
    779 
    780         long notSent = _context.bandwidthLimiter().getTotalWastedOutboundBytes();
    781         long notReceived = _context.bandwidthLimiter().getTotalWastedInboundBytes();
    782 
    783         buf.append("<li> ").append(notSent).append(" bytes outbound bytes unused, ");
    784         buf.append(notReceived).append(" bytes inbound bytes unused</li>");
    785 
    786         DecimalFormat fmt = new DecimalFormat("##0.00");
    787 
    788         // we use the unadjusted time, since thats what getWhenStarted is based off
    789         long lifetime = _context.clock().now()-_context.clock().getOffset() - getWhenStarted();
    790         lifetime /= 1000;
    791         if ( (sent > 0) && (received > 0) ) {
    792             double sendKBps = sent / (lifetime*1024.0);
    793             double receivedKBps = received / (lifetime*1024.0);
    794             buf.append("<li>Lifetime rate: ");
    795             buf.append(fmt.format(sendKBps)).append("KBps sent ");
    796             buf.append(fmt.format(receivedKBps)).append("KBps received");
    797             buf.append("</li>");
    798         }
    799         if ( (notSent > 0) && (notReceived > 0) ) {
    800             double notSendKBps = notSent / (lifetime*1024.0);
    801             double notReceivedKBps = notReceived / (lifetime*1024.0);
    802             buf.append("<li>Lifetime unused rate: ");
    803             buf.append(fmt.format(notSendKBps)).append("KBps outbound unused  ");
    804             buf.append(fmt.format(notReceivedKBps)).append("KBps inbound unused");
    805             buf.append("</li>");
    806         }
    807        
    808         RateStat sendRate = _context.statManager().getRate("transport.sendMessageSize");
    809         for (int i = 0; i < sendRate.getPeriods().length; i++) {
    810             Rate rate = sendRate.getRate(sendRate.getPeriods()[i]);
    811             double bytes = rate.getLastTotalValue();
    812             long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime();
    813             if (ms <= 0) {
    814                 bytes = 0;
    815                 ms = 1;
    816             }
    817             buf.append("<li>");
    818             buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous send avg: ");
    819             double bps = bytes*1000.0d/ms;
    820             if (bps > 2048) {
    821                 bps /= 1024.0d;
    822                 buf.append(fmt.format(bps)).append(" KBps");
    823             } else {
    824                 buf.append(fmt.format(bps)).append(" Bps");
    825             }
    826             buf.append(" over ").append((long)bytes).append(" bytes");
    827             buf.append("</li><li>");
    828             buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period send avg: ");
    829             bps = bytes*1000.0d/(rate.getPeriod());
    830             if (bps > 2048) {
    831                 bps /= 1024.0d;
    832                 buf.append(fmt.format(bps)).append(" KBps");
    833             } else {
    834                 buf.append(fmt.format(bps)).append(" Bps");
    835             }
    836             buf.append(" over ").append((long)bytes).append(" bytes");
    837             buf.append("</li>");
    838         }
    839 
    840         RateStat receiveRate = _context.statManager().getRate("transport.receiveMessageSize");
    841         for (int i = 0; i < receiveRate.getPeriods().length; i++) {
    842             Rate rate = receiveRate.getRate(receiveRate.getPeriods()[i]);
    843             double bytes = rate.getLastTotalValue();
    844             long ms = rate.getLastTotalEventTime();
    845             if (ms <= 0) {
    846                 bytes = 0;
    847                 ms = 1;
    848             }
    849             buf.append("<li>");
    850             buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" instantaneous receive avg: ");
    851             double bps = bytes*1000.0d/ms;
    852             if (bps > 2048) {
    853                 bps /= 1024.0d;
    854                 buf.append(fmt.format(bps)).append(" KBps ");
    855             } else {
    856                 buf.append(fmt.format(bps)).append(" Bps ");
    857             }
    858             buf.append(" over ").append((long)bytes).append(" bytes");
    859             buf.append("</li><li>");
    860             buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period receive avg: ");
    861             bps = bytes*1000.0d/(rate.getPeriod());
    862             if (bps > 2048) {
    863                 bps /= 1024.0d;
    864                 buf.append(fmt.format(bps)).append(" KBps");
    865             } else {
    866                 buf.append(fmt.format(bps)).append(" Bps");
    867             }
    868             buf.append(" over ").append((long)bytes).append(" bytes");
    869             buf.append("</li>");
    870         }
    871 
    872         buf.append("</ul>\n");
    873         buf.append("<i>Instantaneous averages count how fast the transfers go when we're trying to transfer data, ");
    874         buf.append("while period averages count how fast the transfers go across the entire period, even when we're not ");
    875         buf.append("trying to transfer data.  Lifetime averages count how many elephants there are on the moon [like anyone reads this text]</i>");
    876         buf.append("\n");
    877        
    878         out.write(buf.toString());
    879        
    880         _context.bandwidthLimiter().renderStatusHTML(out);
    881 
    882         out.write("<hr><a name=\"clients\"> </a>\n");
    883        
    884         _context.clientManager().renderStatusHTML(out);
    885        
    886         out.write("\n<hr><a name=\"transports\"> </a>\n");
    887        
    888         _context.commSystem().renderStatusHTML(out);
    889        
    890         out.write("\n<hr><a name=\"profiles\"> </a>\n");
    891        
    892         _context.peerManager().renderStatusHTML(out);
    893        
    894         out.write("\n<hr><a name=\"tunnels\"> </a>\n");
    895        
    896         _context.tunnelManager().renderStatusHTML(out);
    897        
    898         out.write("\n<hr><a name=\"jobs\"> </a>\n");
    899        
    900         _context.jobQueue().renderStatusHTML(out);
    901        
    902         out.write("\n<hr><a name=\"shitlist\"> </a>\n");
    903        
    904         _context.shitlist().renderStatusHTML(out);
    905        
    906         out.write("\n<hr><a name=\"pending\"> </a>\n");
    907        
    908         _context.messageRegistry().renderStatusHTML(out);
    909        
    910         out.write("\n<hr><a name=\"netdb\"> </a>\n");
    911        
    912         _context.netDb().renderLeaseSetHTML(out);
    913         _context.netDb().renderStatusHTML(out);
    914        
    915         buf.setLength(0);
    916         buf.append("\n<hr><a name=\"logs\"> </a>\n");   
    917         List msgs = _context.logManager().getBuffer().getMostRecentMessages();
    918         buf.append("\n<h2>Most recent console messages:</h2><table>\n");
    919         for (Iterator iter = msgs.iterator(); iter.hasNext(); ) {
    920             String msg = (String)iter.next();
    921             buf.append("<tr><td align=\"left\"><pre>");
    922             appendLogMessage(buf, msg);
    923             buf.append("</pre></td></tr>\n");
    924         }
    925         buf.append("</table>\n");
    926 ***********/
    927         out.write(buf.toString());
    928         out.flush();
    929     }
    930    
    931     //private static int MAX_MSG_LENGTH = 120;
    932     private static final void appendLogMessage(StringBuilder buf, String msg) {
    933         // disable this code for the moment because i think it
    934         // looks ugly (on the router console)
    935         //if (true) {
    936             buf.append(msg);
    937             return;
    938         //}
    939 /******
    940         if (msg.length() < MAX_MSG_LENGTH) {
    941             buf.append(msg);
    942             return;
    943         }
    944         int newline = msg.indexOf('\n');
    945         int len = msg.length();
    946         while ( (msg != null) && (len > 0) ) {
    947             if (newline < 0) {
    948                 // last line, trim if necessary
    949                 if (len > MAX_MSG_LENGTH)
    950                     msg = msg.substring(len-MAX_MSG_LENGTH);
    951                 buf.append(msg);
    952                 return;
    953             } else if (newline >= MAX_MSG_LENGTH) {
    954                 // not the last line, but too long. 
    955                 // trim the first few chars
    956                 String cur = msg.substring(newline-MAX_MSG_LENGTH, newline).trim();
    957                 msg = msg.substring(newline+1);
    958                 if (cur.length() > 0)
    959                     buf.append(cur).append('\n');
    960             } else {
    961                 // newline <= max_msg_length, so its not the last,
    962                 // and not too long
    963                 String cur = msg.substring(0, newline).trim();
    964                 msg = msg.substring(newline+1);
    965                 if (cur.length() > 0)
    966                     buf.append(cur).append('\n');
    967             }
    968             newline = msg.indexOf('\n');
    969             len = msg.length();
    970         }
    971 ******/
    972     }
    973    
    974     /** main-ish method for testing appendLogMessage */
    975 /******
    976     private static final void testAppendLog() {
    977         StringBuilder buf = new StringBuilder(1024);
    978         Router.appendLogMessage(buf, "hi\nhow are you\nh0h0h0");
    979         System.out.println("line: [" + buf.toString() + "]");
    980         buf.setLength(0);
    981         Router.appendLogMessage(buf, "\nfine thanks\nh0h0h0");
    982         System.out.println("line: [" + buf.toString() + "]");
    983         buf.setLength(0);
    984         Router.appendLogMessage(buf, "liar\nblah blah\n");
    985         System.out.println("line: [" + buf.toString() + "]");
    986         buf.setLength(0);
    987         Router.appendLogMessage(buf, "\n");
    988         System.out.println("line: [" + buf.toString() + "]");
    989         buf.setLength(0);
    990         Router.appendLogMessage(buf, "");
    991         System.out.println("line: [" + buf.toString() + "]");
    992         buf.setLength(0);
    993         Router.appendLogMessage(buf, ".........10........20........30........40........50........6");
    994         System.out.println("line: [" + buf.toString() + "]");
    995         buf.setLength(0);
    996         Router.appendLogMessage(buf, ".........10........\n20........30........40........50........6");
    997         System.out.println("line: [" + buf.toString() + "]");
    998         buf.setLength(0);
    999         Router.appendLogMessage(buf, ".........10........20\n........30........40........50........6");
    1000         System.out.println("line: [" + buf.toString() + "]");
    1001         buf.setLength(0);
    1002         Router.appendLogMessage(buf, ".........10.......\n.20........30........40........50........6");
    1003         System.out.println("line: [" + buf.toString() + "]");
    1004         buf.setLength(0);
    1005         Router.appendLogMessage(buf, "\n.........10........20........30........40........50........6");
    1006         System.out.println("line: [" + buf.toString() + "]");
    1007         buf.setLength(0);
    1008     }
    1009 ******/
    1010 
    1011730    public static final int EXIT_GRACEFUL = 2;
    1012731    public static final int EXIT_HARD = 3;
Note: See TracChangeset for help on using the changeset viewer.