Changeset d189c39 for apps


Ignore:
Timestamp:
Apr 16, 2018 2:34:41 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
76999cc
Parents:
b9bc254
Message:

Console: Add links to bandwidth graphs on /tunnels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/helpers/TunnelRenderer.java

    rb9bc254 rd189c39  
    2222import net.i2p.router.web.HelperBase;
    2323import net.i2p.router.web.Messages;
     24import net.i2p.stat.Rate;
    2425import net.i2p.stat.RateStat;
    2526
     
    3738
    3839    public void renderStatusHTML(Writer out) throws IOException {
    39         out.write("<h3 class=\"tabletitle\" id=\"exploratorytunnels\"><a name=\"exploratory\" ></a>" + _t("Exploratory tunnels") + " <a href=\"/configtunnels#exploratory\" title=\"" + _t("Configure tunnels") + "\">[" + _t("configure") + "]</a></h3>\n");
    40         renderPool(out, _context.tunnelManager().getInboundExploratoryPool(), _context.tunnelManager().getOutboundExploratoryPool());
     40        TunnelPool ei = _context.tunnelManager().getInboundExploratoryPool();
     41        TunnelPool eo = _context.tunnelManager().getOutboundExploratoryPool();
     42        out.write("<h3 class=\"tabletitle\" id=\"exploratorytunnels\"><a name=\"exploratory\" ></a>" + _t("Exploratory tunnels"));
     43        // links are set to float:right in CSS so they will be displayed in reverse order
     44        out.write(" <a href=\"/configtunnels#exploratory\" title=\"" + _t("Configure tunnels") + "\">[" + _t("configure") + "]</a>");
     45        writeGraphLinks(out, ei, eo);
     46        out.write("</h3>\n");
     47        renderPool(out, ei, eo);
    4148
    4249        List<Hash> destinations = null;
     
    6572            out.write("<h3 class=\"tabletitle\" id=\"" + client.toBase64().substring(0,4)
    6673                      + "\" >" + _t("Client tunnels for") + ' ' + DataHelper.escapeHTML(_t(name)));
    67             if (isLocal)
    68                 out.write(" <a href=\"/configtunnels#" + client.toBase64().substring(0,4) +"\" title=\"" + _t("Configure tunnels for session") + "\">[" + _t("configure") + "]</a></h3>\n");
    69             else
     74            if (isLocal) {
     75                // links are set to float:right in CSS so they will be displayed in reverse order
     76                out.write(" <a href=\"/configtunnels#" + client.toBase64().substring(0,4) +"\" title=\"" + _t("Configure tunnels for session") + "\">[" + _t("configure") + "]</a>");
     77                writeGraphLinks(out, in, outPool);
     78                out.write("</h3>\n");
     79            } else {
    7080                out.write(" (" + _t("dead") + ")</h3>\n");
     81            }
    7182            if (in != null) {
    7283                // list aliases
     
    168179            out.write("<div class=\"statusnotes\"><b>" + _t("none") + "</b></div>\n");
    169180        out.write("<div class=\"statusnotes\"><b>" + _t("Lifetime bandwidth usage") + ":&nbsp;&nbsp;" + DataHelper.formatSize2Decimal(processed*1024) + "B</b></div>\n");
    170         } else {
     181        } else {   // bwShare > 12
    171182            out.write("<div class=\"statusnotes noparticipate\"><b>" + _t("Not enough shared bandwidth to build participating tunnels.") +
    172183                      "</b> <a href=\"config\">[" + _t("Configure") + "]</a></div>\n");
     
    203214    }
    204215
     216    /** @since 0.9.35 */
     217    private void writeGraphLinks(Writer out, TunnelPool in, TunnelPool outPool) throws IOException {
     218        if (in == null || outPool == null)
     219            return;
     220        String irname = in.getRateName();
     221        String orname = outPool.getRateName();
     222        RateStat irs = _context.statManager().getRate(irname);
     223        RateStat ors = _context.statManager().getRate(orname);
     224        if (irs == null || ors == null)
     225            return;
     226        Rate ir = irs.getRate(5*60*1000L);
     227        Rate or = ors.getRate(5*60*1000L);
     228        if (ir == null || or == null)
     229            return;
     230        final String tgd = _t("Graph Data");
     231        final String tcg = _t("Configure Graph Display");
     232        // links are set to float:right in CSS so they will be displayed in reverse order
     233        if (or.getSummaryListener() != null) {
     234            out.write("<a href=\"graph?stat=" + orname + ".300000&amp;w=600&amp;h=200\">" +
     235                      "<img src=\"/themes/console/images/outbound.png\" alt=\"" + tgd + "\" title=\"" + tgd + "\"></a>");
     236        } else {
     237            out.write("<a href=\"configstats#" + orname + "\">" +
     238                      "<img src=\"/themes/console/images/outbound.png\" alt=\"" + tcg + "\" title=\"" + tcg + "\"></a>");
     239        }
     240        if (ir.getSummaryListener() != null) {
     241            out.write("<a href=\"graph?stat=" + irname + ".300000&amp;w=600&amp;h=200\">" +
     242                      "<img src=\"/themes/console/images/inbound.png\" alt=\"" + tgd + "\" title=\"" + tgd + "\"></a> ");
     243        } else {
     244            out.write("<a href=\"configstats#" + irname + "\">" +
     245                      "<img src=\"/themes/console/images/inbound.png\" alt=\"" + tcg + "\" title=\"" + tcg + "\"></a>");
     246        }
     247    }
     248
    205249    private void renderPool(Writer out, TunnelPool in, TunnelPool outPool) throws IOException {
    206250        List<TunnelInfo> tunnels = null;
     
    236280        }
    237281        out.write("</tr>\n");
     282        final String tib = _t("Inbound");
     283        final String tob = _t("Outbound");
    238284        for (int i = 0; i < tunnels.size(); i++) {
    239285            TunnelInfo info = tunnels.get(i);
     
    244290            boolean isInbound = info.isInbound();
    245291            if (isInbound)
    246                 out.write("<tr><td class=\"cells\" align=\"center\"><img src=\"/themes/console/images/inbound.png\" alt=\"Inbound\" title=\"" +
    247                           _t("Inbound") + "\"></td>");
    248             else
    249                 out.write("<tr><td class=\"cells\" align=\"center\"><img src=\"/themes/console/images/outbound.png\" alt=\"Outbound\" title=\"" +
    250                           _t("Outbound") + "\"></td>");
     292                out.write("<tr><td class=\"cells\" align=\"center\"><img src=\"/themes/console/images/inbound.png\" alt=\"" + tib + "\" title=\"" +
     293                          tib + "\"></td>");
     294            else
     295                out.write("<tr><td class=\"cells\" align=\"center\"><img src=\"/themes/console/images/outbound.png\" alt=\"" + tob + "\" title=\"" +
     296                          tob + "\"></td>");
    251297            out.write("<td class=\"cells\" align=\"center\">" + DataHelper.formatDuration2(timeLeft) + "</td>\n");
    252298            int count = info.getProcessedMessagesCount() * 1024 / 1000;
     
    294340            List<?> pending = in.listPending();
    295341            if (!pending.isEmpty()) {
    296                 out.write("<div class=\"statusnotes\"><center><b>" + _t("Build in progress") + ":&nbsp;&nbsp;" + pending.size() + " " + _t("inbound") + "</b></center></div>\n");
     342                out.write("<div class=\"statusnotes\"><center><b>" + _t("Build in progress") + ":&nbsp;&nbsp;" + pending.size() + " " + tib + "</b></center></div>\n");
    297343                live += pending.size();
    298344            }
     
    302348            List<?> pending = outPool.listPending();
    303349            if (!pending.isEmpty()) {
    304                 out.write("<div class=\"statusnotes\"><center><b>" + _t("Build in progress") + ":&nbsp;&nbsp;" + pending.size() + " " + _t("outbound") + "</b></center></div>\n");
     350                out.write("<div class=\"statusnotes\"><center><b>" + _t("Build in progress") + ":&nbsp;&nbsp;" + pending.size() + " " + tob + "</b></center></div>\n");
    305351                live += pending.size();
    306352            }
Note: See TracChangeset for help on using the changeset viewer.