Changeset 21e47e6


Ignore:
Timestamp:
Apr 13, 2013 12:13:55 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
8bfe3f6
Parents:
49cc6b5
Message:
  • Console: Add /graph support for bw.combined, consolidate

rendering code (ticket #890)

Files:
7 edited

Legend:

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

    r49cc6b5 r21e47e6  
    127127    /**
    128128     *  For single stat page
     129     *  @param "bw.combined" treated specially
    129130     *  @since 0.9
    130131     */
     
    152153
    153154            if (hasTx && hasRx && !_showEvents) {
    154                 _out.write("<a href=\"viewstat?stat=bw.combined"
    155                            + "&amp;periodCount=" + (3 * _periodCount )
    156                            + "&amp;width=" + (3 * _width)
    157                            + "&amp;height=" + (3 * _height)
     155                _out.write("<a href=\"graph?stat=bw.combined"
     156                           + "&amp;c=" + (3 * _periodCount )
     157                           + "&amp;w=" + (3 * _width)
     158                           + "&amp;h=" + (3 * _height)
    158159                           + "\">");
    159160                String title = _("Combined bandwidth graph");
     
    201202
    202203    /**
    203      *  For single stat page
     204     *  For single stat page;
     205     *  stat = "bw.combined" treated specially
     206     *
    204207     *  @since 0.9
    205208     */
     
    209212                return "";
    210213            if (_stat == null) {
    211                 _out.write("No stat");
     214                _out.write("No stat specified");
    212215                return "";
    213216            }
    214             List<Rate> rates = StatSummarizer.instance().parseSpecs(_stat);
    215             if (rates.size() != 1) {
    216                 _out.write("Graphs not enabled for " + _stat);
    217                 return "";
    218             }
    219             Rate r = rates.get(0);
     217            long period;
     218            String name, displayName;
     219            if (_stat.equals("bw.combined")) {
     220                period = 60000;
     221                name = _stat;
     222                displayName = _("Bandwidth usage");
     223            } else {
     224                List<Rate> rates = StatSummarizer.instance().parseSpecs(_stat);
     225                if (rates.size() != 1) {
     226                    _out.write("Graphs not enabled for " + _stat);
     227                    return "";
     228                }
     229                Rate r = rates.get(0);
     230                period = r.getPeriod();
     231                name = r.getRateStat().getName();
     232                displayName = name;
     233            }
    220234            _out.write("<h3>");
    221             _out.write(_("{0} for {1}", r.getRateStat().getName(), DataHelper.formatDuration2(_periodCount * r.getPeriod())));
     235            _out.write(_("{0} for {1}", displayName, DataHelper.formatDuration2(_periodCount * period)));
    222236            if (_end > 0)
    223                 _out.write(' ' + _("ending {0} ago", DataHelper.formatDuration2(_end * r.getPeriod())));
     237                _out.write(' ' + _("ending {0} ago", DataHelper.formatDuration2(_end * period)));
    224238
    225239            _out.write("</h3><img class=\"statimage\" border=\"0\""
    226240                       + " src=\"viewstat.jsp?stat="
    227                        + r.getRateStat().getName()
     241                       + name
    228242                       + "&amp;showEvents=" + _showEvents
    229                        + "&amp;period=" + r.getPeriod()
     243                       + "&amp;period=" + period
    230244                       + "&amp;periodCount=" + _periodCount
    231245                       + "&amp;end=" + _end
     
    303317            _out.write("<br>");
    304318            _out.write(link(_stat, !_showEvents, _periodCount, _end, _width, _height));
    305             _out.write(_showEvents ? _("Plot averages") : _("plot events"));
     319            if (!_stat.equals("bw.combined"))
     320                _out.write(_showEvents ? _("Plot averages") : _("plot events"));
    306321            _out.write("</a>");
    307322
  • apps/routerconsole/java/src/net/i2p/router/web/StatSummarizer.java

    r49cc6b5 r21e47e6  
    246246                lsnr.getData().exportXml(out);
    247247                out.write(("<!-- Rate: " + lsnr.getRate().getRateStat().getName() + " for period " + lsnr.getRate().getPeriod() + " -->\n").getBytes());
    248                 out.write(("<!-- Average data soure name: " + lsnr.getName() + " event count data source name: " + lsnr.getEventName() + " -->\n").getBytes());
     248                out.write(("<!-- Average data source name: " + lsnr.getName() + " event count data source name: " + lsnr.getEventName() + " -->\n").getBytes());
    249249                return true;
    250250            }
     
    255255    /**
    256256     *  This does the two-data bandwidth graph only.
    257      *  For all other graphs see SummaryRenderer
     257     *  For all other graphs see renderPng() above.
    258258     *  Synchronized to conserve memory.
     259     *
     260     *  @param end number of periods before now
    259261     *  @return success
    260262     */
    261263    public boolean renderRatePng(OutputStream out, int width, int height, boolean hideLegend,
    262264                                              boolean hideGrid, boolean hideTitle, boolean showEvents,
    263                                               int periodCount, boolean showCredit) throws IOException {
     265                                              int periodCount, int end, boolean showCredit) throws IOException {
    264266        try {
    265267            try {
     
    267269            } catch (InterruptedException ie) {}
    268270            return locked_renderRatePng(out, width, height, hideLegend, hideGrid, hideTitle, showEvents,
    269                                         periodCount, showCredit);
     271                                        periodCount, end, showCredit);
    270272        } finally {
    271273            _sem.release();
     
    275277    private boolean locked_renderRatePng(OutputStream out, int width, int height, boolean hideLegend,
    276278                                              boolean hideGrid, boolean hideTitle, boolean showEvents,
    277                                               int periodCount, boolean showCredit) throws IOException {
     279                                              int periodCount, int end, boolean showCredit) throws IOException {
    278280
    279281        // go to some trouble to see if we have the data for the combined bw graph
     
    290292            throw new IOException("no rates for combined graph");
    291293
    292         long end = _context.clock().now() - 75*1000;
    293294        if (width > GraphHelper.MAX_X)
    294295            width = GraphHelper.MAX_X;
     
    299300        else if (height <= 0)
    300301            height = GraphHelper.DEFAULT_Y;
    301         if (periodCount <= 0 || periodCount > txLsnr.getRows())
    302             periodCount = txLsnr.getRows();
    303         long period = 60*1000;
    304         long start = end - period*periodCount;
    305         //long begin = System.currentTimeMillis();
    306         ImageOutputStream ios = null;
    307         try {
    308             RrdGraphDef def = new RrdGraphDef();
    309             def.setTimeSpan(start/1000, end/1000);
    310             def.setMinValue(0d);
    311             def.setBase(1024);
    312             String title = _("Bandwidth usage");
    313             if (!hideTitle)
    314                 def.setTitle(title);
    315             long started = _context.router().getWhenStarted();
    316             if (started > start && started < end)
    317                 def.vrule(started / 1000, SummaryRenderer.RESTART_BAR_COLOR, null, 4.0f);  // no room for legend
    318             String sendName = SummaryListener.createName(_context, "bw.sendRate.60000");
    319             String recvName = SummaryListener.createName(_context, "bw.recvRate.60000");
    320             def.datasource(sendName, txLsnr.getData().getPath(), sendName, SummaryListener.CF, txLsnr.getBackendName());
    321             def.datasource(recvName, rxLsnr.getData().getPath(), recvName, SummaryListener.CF, rxLsnr.getBackendName());
    322             def.area(sendName, Color.BLUE, _("Outbound Bytes/sec"));
    323             //def.line(sendName, Color.BLUE, "Outbound bytes/sec", 3);
    324             def.line(recvName, Color.RED, _("Inbound Bytes/sec") + "\\r", 3);
    325             //def.area(recvName, Color.RED, "Inbound bytes/sec@r");
    326             if (!hideLegend) {
    327                 def.gprint(sendName, SummaryListener.CF, _("Out average") + ": %.2f %s" + _("Bps"));
    328                 def.gprint(sendName, "MAX", ' ' + _("max") + ": %.2f %S" + _("Bps") + "\\r");
    329                 def.gprint(recvName, SummaryListener.CF, _("In average") + ": %.2f %S" + _("Bps"));
    330                 def.gprint(recvName, "MAX", ' ' + _("max") + ": %.2f %S" + _("Bps") + "\\r");
    331                 // '07-Jul 21:09 UTC' with month name in the system locale
    332                 SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM HH:mm");
    333                 def.comment(sdf.format(new Date(start)) + " -- " + sdf.format(new Date(end)) + " UTC\\r");
    334             }
    335             if (!showCredit)
    336                 def.setShowSignature(false);
    337             if (hideLegend)
    338                 def.setNoLegend(true);
    339             if (hideGrid) {
    340                 def.setDrawXGrid(false);
    341                 def.setDrawYGrid(false);
    342             }
    343             //System.out.println("rendering: path=" + path + " dsNames[0]=" + dsNames[0] + " dsNames[1]=" + dsNames[1] + " lsnr.getName=" + _listener.getName());
    344             def.setAntiAliasing(false);
    345             //System.out.println("Rendering: \n" + def.exportXmlTemplate());
    346             //System.out.println("*****************\nData: \n" + _listener.getData().dump());
    347             def.setWidth(width);
    348             def.setHeight(height);
    349             def.setImageFormat("PNG");
    350             def.setLazy(true);
    351 
    352             RrdGraph graph = new RrdGraph(def);
    353             //System.out.println("Graph created");
    354             int totalWidth = graph.getRrdGraphInfo().getWidth();
    355             int totalHeight = graph.getRrdGraphInfo().getHeight();
    356             BufferedImage img = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_USHORT_565_RGB);
    357             Graphics gfx = img.getGraphics();
    358             graph.render(gfx);
    359             ios = new MemoryCacheImageOutputStream(out);
    360             ImageIO.write(img, "png", ios);
    361 
    362             //File t = File.createTempFile("jrobinData", ".xml");
    363             //_listener.getData().dumpXml(new FileOutputStream(t));
    364             //System.out.println("plotted: " + (data != null ? data.length : 0) + " bytes in " + timeToPlot
    365             //                   ); // + ", data written to " + t.getAbsolutePath());
    366             return true;
    367         } catch (RrdException re) {
    368             _log.error("Error rendering", re);
    369             throw new IOException("Error plotting: " + re.getMessage());
    370         } catch (IOException ioe) {
    371             if (_log.shouldLog(Log.WARN))
    372                 _log.warn("Error rendering", ioe);
    373             throw ioe;
    374         } catch (OutOfMemoryError oom) {
    375             _log.error("Error rendering", oom);
    376             throw new IOException("Error plotting: " + oom.getMessage());
    377         } finally {
    378             // this does not close the underlying stream
    379             if (ios != null) try {ios.close();} catch (IOException ioe) {}
    380         }
     302        txLsnr.renderPng(out, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount,
     303                         end, showCredit, rxLsnr, _("Bandwidth usage"));
     304        return true;
    381305    }
    382306   
  • apps/routerconsole/java/src/net/i2p/router/web/SummaryListener.java

    r49cc6b5 r21e47e6  
    188188
    189189    /**
     190     *  Single graph.
     191     *
    190192     *  @param end number of periods before now
    191193     */
     
    193195                          boolean hideTitle, boolean showEvents, int periodCount,
    194196                          int end, boolean showCredit) throws IOException {
     197        renderPng(out, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount,
     198                  end, showCredit, null, null);
     199    }
     200
     201    /**
     202     *  Single or two-data-source graph.
     203     *
     204     *  @param lsnr2 2nd data source to plot on same graph, or null. Not recommended for events.
     205     *  @param titleOverride If non-null, overrides the title
     206     *  @since 0.9.6
     207     */
     208    public void renderPng(OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid,
     209                          boolean hideTitle, boolean showEvents, int periodCount,
     210                          int end, boolean showCredit, SummaryListener lsnr2, String titleOverride) throws IOException {
    195211        if (_renderer == null || _db == null)
    196212            throw new IOException("No RRD, check logs for previous errors");
    197         _renderer.render(out, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount, end, showCredit);
     213        _renderer.render(out, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount,
     214                         end, showCredit, lsnr2, titleOverride);
    198215    }
    199216
  • apps/routerconsole/java/src/net/i2p/router/web/SummaryRenderer.java

    r49cc6b5 r21e47e6  
    2828/**
    2929 *  Generate the RRD graph png images,
    30  *  except for the combined rate graph, which is
    31  *  generated in StatSummarizer.
     30 *  including the combined rate graph.
    3231 *
    3332 *  @since 0.6.1.13
     
    3736    private final SummaryListener _listener;
    3837    private final I2PAppContext _context;
    39     static final Color RESTART_BAR_COLOR = new Color(255, 144, 0, 224);
     38    private static final Color RESTART_BAR_COLOR = new Color(255, 144, 0, 224);
    4039
    4140    public SummaryRenderer(I2PAppContext ctx, SummaryListener lsnr) {
     
    5251     *
    5352     * @deprecated unsed
     53     * @throws UnsupportedOperationException always
    5454     */
    5555    public static synchronized void render(I2PAppContext ctx, OutputStream out, String filename) throws IOException {
     56        throw new UnsupportedOperationException();
     57/*****
    5658        long end = ctx.clock().now() - 60*1000;
    5759        long start = end - 60*1000*SummaryListener.PERIODS;
     
    8183            throw ioe;
    8284        }
     85*****/
    8386    }
    8487
     
    8790
    8891    /**
     92     *  Single graph.
     93     *
    8994     *  @param endp number of periods before now
    9095     */
     
    9297                       boolean hideTitle, boolean showEvents, int periodCount,
    9398                       int endp, boolean showCredit) throws IOException {
     99        render(out, width, height, hideLegend, hideGrid, hideTitle,
     100               showEvents, periodCount, endp, showCredit, null, null);
     101    }
     102
     103    /**
     104     *  Single or two-data-source graph.
     105     *
     106     *  @param lsnr2 2nd data source to plot on same graph, or null. Not recommended for events.
     107     *  @param titleOverride If non-null, overrides the title
     108     *  @since 0.9.6 consolidated from StatSummarizer for bw.combined
     109     */
     110    public void render(OutputStream out, int width, int height, boolean hideLegend, boolean hideGrid,
     111                       boolean hideTitle, boolean showEvents, int periodCount,
     112                       int endp, boolean showCredit, SummaryListener lsnr2, String titleOverride) throws IOException {
    94113        long end = _listener.now() - 75*1000;
    95114        long period = _listener.getRate().getPeriod();
     
    110129                && !showEvents)
    111130                def.setBase(1024);
    112             if (!hideTitle) {
     131            if (titleOverride != null) {
     132                def.setTitle(titleOverride);
     133            } else if (!hideTitle) {
    113134                String title;
    114135                String p;
     
    147168
    148169            def.datasource(plotName, path, plotName, SummaryListener.CF, _listener.getBackendName());
    149             if (descr.length() > 0)
     170            if (descr.length() > 0) {
    150171                def.area(plotName, Color.BLUE, descr + "\\r");
    151             else
     172            } else {
    152173                def.area(plotName, Color.BLUE);
     174            }
    153175            if (!hideLegend) {
    154176                def.gprint(plotName, SummaryListener.CF, _("avg") + ": %.2f %s");
    155177                def.gprint(plotName, "MAX", ' ' + _("max") + ": %.2f %S");
    156178                def.gprint(plotName, "LAST", ' ' + _("now") + ": %.2f %S\\r");
     179            }
     180            String plotName2 = null;
     181            if (lsnr2 != null) {
     182                String dsNames2[] = lsnr2.getData().getDsNames();
     183                plotName2 = dsNames2[0];
     184                String path2 = lsnr2.getData().getPath();
     185                String descr2 = _(lsnr2.getRate().getRateStat().getDescription());
     186                def.datasource(plotName2, path2, plotName2, SummaryListener.CF, lsnr2.getBackendName());
     187                def.line(plotName2, Color.RED, descr2 + "\\r", 3);
     188                if (!hideLegend) {
     189                    def.gprint(plotName2, SummaryListener.CF, _("avg") + ": %.2f %s");
     190                    def.gprint(plotName2, "MAX", ' ' + _("max") + ": %.2f %S");
     191                    def.gprint(plotName2, "LAST", ' ' + _("now") + ": %.2f %S\\r");
     192                }
     193            }
     194            if (!hideLegend) {
    157195                // '07-Jul 21:09 UTC' with month name in the system locale
    158196                SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM HH:mm");
  • apps/routerconsole/jsp/viewstat.jsp

    r49cc6b5 r21e47e6  
    6161        str = request.getParameter("end");
    6262        if (str != null) try { end = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
    63         boolean hideLegend = Boolean.valueOf(""+request.getParameter("hideLegend")).booleanValue();
    64         boolean hideGrid = Boolean.valueOf(""+request.getParameter("hideGrid")).booleanValue();
    65         boolean hideTitle = Boolean.valueOf(""+request.getParameter("hideTitle")).booleanValue();
    66         boolean showEvents = Boolean.valueOf(""+request.getParameter("showEvents")).booleanValue();
     63        boolean hideLegend = Boolean.parseBoolean((String) request.getParameter("hideLegend"));
     64        boolean hideGrid = Boolean.parseBoolean((String) request.getParameter("hideGrid"));
     65        boolean hideTitle = Boolean.parseBoolean((String) request.getParameter("hideTitle"));
     66        boolean showEvents = Boolean.parseBoolean((String) request.getParameter("showEvents"));
    6767        boolean showCredit = false;
    6868        if (request.getParameter("showCredit") != null)
    69           showCredit = Boolean.valueOf(""+request.getParameter("showCredit")).booleanValue();
     69          showCredit = Boolean.parseBoolean((String) request.getParameter("showCredit"));
    7070        if (fakeBw)
    71             rendered = net.i2p.router.web.StatSummarizer.instance().renderRatePng(cout, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount, showCredit);
     71            rendered = net.i2p.router.web.StatSummarizer.instance().renderRatePng(cout, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount, end, showCredit);
    7272        else
    7373            rendered = net.i2p.router.web.StatSummarizer.instance().renderPng(rate, cout, width, height, hideLegend, hideGrid, hideTitle, showEvents, periodCount, end, showCredit);
  • history.txt

    r49cc6b5 r21e47e6  
     12013-04-13 zzz
     2 * Console: Add /graph support for bw.combined, consolidate
     3            rendering code (ticket #890)
     4 * i2psnark:
     5   - Limit number of torrents displayed; add previous/next page buttons
     6   - Only register one instance with UpdateManager
     7
    182013-04-10 zzz
    29 * Jetty: Upgrade to Jetty 7.6.10.v20130312
  • router/java/src/net/i2p/router/RouterVersion.java

    r49cc6b5 r21e47e6  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 2;
     21    public final static long BUILD = 3;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.