Search in sources :

Example 21 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class StatsGenerator method renderRate.

private void renderRate(String name, StringBuilder buf, boolean showAll) {
    RateStat rate = _context.statManager().getRate(name);
    String d = rate.getDescription();
    if (!"".equals(d)) {
        buf.append("<span class=\"statsLongName\"><i>");
        buf.append(d);
        buf.append("</i></span><br>");
    }
    if (rate.getLifetimeEventCount() <= 0) {
        buf.append("<ul><li class=\"noevents\">").append(_t("No lifetime events")).append("</li></ul>\n");
        return;
    }
    long now = _context.clock().now();
    long[] periods = rate.getPeriods();
    Arrays.sort(periods);
    buf.append("<ul>");
    for (int i = 0; i < periods.length; i++) {
        Rate curRate = rate.getRate(periods[i]);
        if (curRate.getLastCoalesceDate() <= curRate.getCreationDate())
            break;
        buf.append("<li>");
        renderPeriod(buf, periods[i], _t("rate"));
        if (curRate.getLastEventCount() > 0) {
            buf.append(_t("Average")).append(": ");
            buf.append(num(curRate.getAverageValue()));
            buf.append("; ");
            buf.append(_t("Highest average"));
            buf.append(": ");
            buf.append(num(curRate.getExtremeAverageValue()));
            buf.append(". ");
            // Don't bother to translate
            if (showAll) {
                buf.append("Highest total in a period: ");
                buf.append(num(curRate.getExtremeTotalValue()));
                buf.append(". ");
            }
            // Don't bother to translate
            if (showAll && curRate.getLifetimeTotalEventTime() > 0) {
                buf.append("Saturation: ");
                buf.append(pct(curRate.getLastEventSaturation()));
                buf.append("; Saturated limit: ");
                buf.append(num(curRate.getLastSaturationLimit()));
                buf.append("; Peak saturation: ");
                buf.append(pct(curRate.getExtremeEventSaturation()));
                buf.append("; Peak saturated limit: ");
                buf.append(num(curRate.getExtremeSaturationLimit()));
                buf.append(". ");
            }
            buf.append("<span class=\"nowrap\">");
            buf.append(ngettext("There was 1 event in this period.", "There were {0} events in this period.", (int) curRate.getLastEventCount()));
            buf.append("</span> <span class=\"nowrap\">");
            buf.append(_t("The period ended {0} ago.", DataHelper.formatDuration2(now - curRate.getLastCoalesceDate())));
            buf.append("</span>");
        } else {
            buf.append(" <i>").append(_t("No events")).append(" </i>");
        }
        long numPeriods = curRate.getLifetimePeriods();
        if (numPeriods > 0) {
            double avgFrequency = curRate.getLifetimeEventCount() / (double) numPeriods;
            buf.append("&nbsp;<span class=\"nowrap\">(").append(_t("Average event count")).append(": ");
            buf.append(num(avgFrequency));
            buf.append("; ").append(_t("Events in peak period")).append(": ");
            // This isn't really the highest event count, but the event count during the period with the highest total value.
            buf.append(curRate.getExtremeEventCount());
            buf.append(")</span>");
        }
        if (curRate.getSummaryListener() != null) {
            buf.append("<br><span class=\"statsViewGraphs\"><a href=\"graph?stat=").append(name).append('.').append(periods[i]);
            buf.append("&amp;w=600&amp;h=200\">").append(_t("Graph Data")).append("</a> - ");
            buf.append(" <a href=\"graph?stat=").append(name).append('.').append(periods[i]);
            buf.append("&amp;w=600&amp;h=200&amp;showEvents=true\">").append(_t("Graph Event Count")).append("</a></span>");
        // This can really blow up your browser if you click on it
        // buf.append(" - <a href=\"viewstat.jsp?stat=").append(name);
        // buf.append("&amp;period=").append(periods[i]);
        // buf.append("&amp;format=xml\">").append(_t("Export Data as XML")).append("</a>");
        }
        buf.append("</li>\n");
    }
    // Display the strict average
    buf.append("<li><b>").append(_t("Lifetime average value")).append(":</b> ");
    buf.append(num(rate.getLifetimeAverageValue()));
    buf.append(" (");
    buf.append(ngettext("1 event", "{0} events", (int) rate.getLifetimeEventCount()));
    buf.append(")<br></li>" + "</ul>" + "<br>\n");
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 22 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class SummaryHelper method getFiveMinuteKBps.

/**
 *    @return "x.xx / y.yy {K|M}"
 */
public String getFiveMinuteKBps() {
    if (_context == null)
        return "0 / 0";
    RateStat receiveRate = _context.statManager().getRate("bw.recvRate");
    double in = 0;
    if (receiveRate != null) {
        Rate r = receiveRate.getRate(5 * 60 * 1000);
        if (r != null)
            in = r.getAverageValue();
    }
    RateStat sendRate = _context.statManager().getRate("bw.sendRate");
    double out = 0;
    if (sendRate != null) {
        Rate r = sendRate.getRate(5 * 60 * 1000);
        if (r != null)
            out = r.getAverageValue();
    }
    return formatPair(in, out);
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 23 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class SybilRenderer method addProfilePoints.

private void addProfilePoints(List<RouterInfo> ris, Map<Hash, Points> points) {
    long now = _context.clock().now();
    RateAverages ra = RateAverages.getTemp();
    for (RouterInfo info : ris) {
        Hash h = info.getHash();
        if (_context.banlist().isBanlisted(h))
            addPoints(points, h, POINTS_BANLIST, "Banlisted");
        PeerProfile prof = _context.profileOrganizer().getProfileNonblocking(h);
        if (prof != null) {
            long heard = prof.getFirstHeardAbout();
            if (heard > 0) {
                long age = Math.max(now - heard, 1);
                if (age < 2 * DAY) {
                    // (POINTS_NEW / 48) for every hour under 48, max POINTS_NEW
                    double point = Math.min(POINTS_NEW, (2 * DAY - age) / (2 * DAY / POINTS_NEW));
                    addPoints(points, h, point, "First heard about: " + _t("{0} ago", DataHelper.formatDuration2(age)));
                }
            }
            DBHistory dbh = prof.getDBHistory();
            if (dbh != null) {
                RateStat rs = dbh.getFailedLookupRate();
                if (rs != null) {
                    Rate r = rs.getRate(24 * 60 * 60 * 1000);
                    if (r != null) {
                        r.computeAverages(ra, false);
                        if (ra.getTotalEventCount() > 0) {
                            double avg = 100 * ra.getAverage();
                            if (avg > 40)
                                addPoints(points, h, (avg - 40) / 6.0, "Lookup fail rate " + ((int) avg) + '%');
                        }
                    }
                }
            }
        }
    }
}
Also used : RateStat(net.i2p.stat.RateStat) DBHistory(net.i2p.router.peermanager.DBHistory) RouterInfo(net.i2p.data.router.RouterInfo) Rate(net.i2p.stat.Rate) RateAverages(net.i2p.stat.RateAverages) PeerProfile(net.i2p.router.peermanager.PeerProfile) Hash(net.i2p.data.Hash) ConvertToHash(net.i2p.util.ConvertToHash)

Example 24 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class TunnelRenderer method renderStatusHTML.

public void renderStatusHTML(Writer out) throws IOException {
    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");
    renderPool(out, _context.tunnelManager().getInboundExploratoryPool(), _context.tunnelManager().getOutboundExploratoryPool());
    List<Hash> destinations = null;
    Map<Hash, TunnelPool> clientInboundPools = _context.tunnelManager().getInboundClientPools();
    Map<Hash, TunnelPool> clientOutboundPools = _context.tunnelManager().getOutboundClientPools();
    destinations = new ArrayList<Hash>(clientInboundPools.keySet());
    boolean debug = _context.getBooleanProperty(HelperBase.PROP_ADVANCED);
    for (int i = 0; i < destinations.size(); i++) {
        Hash client = destinations.get(i);
        boolean isLocal = _context.clientManager().isLocal(client);
        if ((!isLocal) && (!debug))
            continue;
        TunnelPool in = clientInboundPools.get(client);
        TunnelPool outPool = clientOutboundPools.get(client);
        if ((in != null && in.getSettings().getAliasOf() != null) || (outPool != null && outPool.getSettings().getAliasOf() != null)) {
            // skip aliases, we will print a header under the main tunnel pool below
            continue;
        }
        // TODO the following code is duplicated in SummaryHelper
        String name = (in != null) ? in.getSettings().getDestinationNickname() : null;
        if ((name == null) && (outPool != null))
            name = outPool.getSettings().getDestinationNickname();
        if (name == null)
            name = client.toBase64().substring(0, 4);
        out.write("<h3 class=\"tabletitle\" id=\"" + client.toBase64().substring(0, 4) + "\" >" + _t("Client tunnels for") + ' ' + DataHelper.escapeHTML(_t(name)));
        if (isLocal)
            out.write(" <a href=\"/configtunnels#" + client.toBase64().substring(0, 4) + "\" title=\"" + _t("Configure tunnels for session") + "\">[" + _t("configure") + "]</a></h3>\n");
        else
            out.write(" (" + _t("dead") + ")</h3>\n");
        if (in != null) {
            // list aliases
            Set<Hash> aliases = in.getSettings().getAliases();
            if (aliases != null) {
                for (Hash a : aliases) {
                    TunnelPool ain = clientInboundPools.get(a);
                    if (ain != null) {
                        String aname = ain.getSettings().getDestinationNickname();
                        if (aname == null)
                            aname = a.toBase64().substring(0, 4);
                        out.write("<h3 class=\"tabletitle\" id=\"" + a.toBase64().substring(0, 4) + "\" >" + _t("Client tunnels for") + ' ' + DataHelper.escapeHTML(_t(aname)));
                        if (isLocal)
                            out.write(" <a href=\"/configtunnels#" + client.toBase64().substring(0, 4) + "\" title=\"" + _t("Configure tunnels for session") + "\">[" + _t("configure") + "]</a></h3>\n");
                        else
                            out.write(" (" + _t("dead") + ")</h3>\n");
                    }
                }
            }
        }
        renderPool(out, in, outPool);
    }
    List<HopConfig> participating = _context.tunnelDispatcher().listParticipatingTunnels();
    out.write("<h3 class=\"tabletitle\" id=\"participating\">" + _t("Participating tunnels") + "</h3>\n");
    int bwShare = getShareBandwidth();
    if (bwShare > 12) {
        // Don't bother re-indenting
        if (!participating.isEmpty()) {
            Collections.sort(participating, new TunnelComparator());
            out.write("<table class=\"tunneldisplay tunnels_participating\"><tr><th>" + _t("Receive on") + "</th><th>" + _t("From") + "</th><th>" + _t("Send on") + "</th><th>" + _t("To") + "</th><th>" + _t("Expiration") + "</th>" + "<th>" + _t("Usage") + "</th><th>" + _t("Rate") + "</th><th>" + _t("Role") + "</th></tr>\n");
        }
        long processed = 0;
        RateStat rs = _context.statManager().getRate("tunnel.participatingMessageCount");
        if (rs != null)
            processed = (long) rs.getRate(10 * 60 * 1000).getLifetimeTotalValue();
        int inactive = 0;
        int displayed = 0;
        for (int i = 0; i < participating.size(); i++) {
            HopConfig cfg = participating.get(i);
            int count = cfg.getProcessedMessagesCount();
            if (count <= 0) {
                inactive++;
                continue;
            }
            // everything that isn't 'recent' is already in the tunnel.participatingMessageCount stat
            processed += cfg.getRecentMessagesCount();
            if (++displayed > DISPLAY_LIMIT)
                continue;
            out.write("<tr>");
            if (cfg.getReceiveTunnel() != null)
                out.write("<td class=\"cells\" align=\"center\" title=\"" + _t("Tunnel identity") + "\"><span class=\"tunnel_id\">" + cfg.getReceiveTunnel().getTunnelId() + "</span></td>");
            else
                out.write("<td class=\"cells\" align=\"center\">n/a</td>");
            if (cfg.getReceiveFrom() != null)
                out.write("<td class=\"cells\" align=\"center\"><span class=\"tunnel_peer\">" + netDbLink(cfg.getReceiveFrom()) + "</span></td>");
            else
                out.write("<td class=\"cells\">&nbsp;</td>");
            if (cfg.getSendTunnel() != null)
                out.write("<td class=\"cells\" align=\"center\" title=\"" + _t("Tunnel identity") + "\"><span class=\"tunnel_id\">" + cfg.getSendTunnel().getTunnelId() + "</span></td>");
            else
                out.write("<td class=\"cells\">&nbsp;</td>");
            if (cfg.getSendTo() != null)
                out.write("<td class=\"cells\" align=\"center\"><span class=\"tunnel_peer\">" + netDbLink(cfg.getSendTo()) + "</span></td>");
            else
                out.write("<td class=\"cells\">&nbsp;</td>");
            long timeLeft = cfg.getExpiration() - _context.clock().now();
            if (timeLeft > 0)
                out.write("<td class=\"cells\" align=\"center\">" + DataHelper.formatDuration2(timeLeft) + "</td>");
            else
                out.write("<td class=\"cells\" align=\"center\">(" + _t("grace period") + ")</td>");
            out.write("<td class=\"cells\" align=\"center\">" + (count * 1024 / 1000) + " KB</td>");
            int lifetime = (int) ((_context.clock().now() - cfg.getCreation()) / 1000);
            if (lifetime <= 0)
                lifetime = 1;
            if (lifetime > 10 * 60)
                lifetime = 10 * 60;
            int bps = 1024 * count / lifetime;
            out.write("<td class=\"cells\" align=\"center\">" + bps + " Bps</td>");
            if (cfg.getSendTo() == null)
                out.write("<td class=\"cells\" align=\"center\">" + _t("Outbound Endpoint") + "</td>");
            else if (cfg.getReceiveFrom() == null)
                out.write("<td class=\"cells\" align=\"center\">" + _t("Inbound Gateway") + "</td>");
            else
                out.write("<td class=\"cells\" align=\"center\">" + _t("Participant") + "</td>");
            out.write("</tr>\n");
        }
        if (!participating.isEmpty())
            out.write("</table>\n");
        if (displayed > DISPLAY_LIMIT)
            out.write("<div class=\"statusnotes\"><b>" + _t("Limited display to the {0} tunnels with the highest usage", DISPLAY_LIMIT) + "</b></div>\n");
        if (inactive > 0)
            out.write("<div class=\"statusnotes\"><b>" + _t("Inactive participating tunnels") + ":&nbsp;&nbsp;" + inactive + "</b></div>\n");
        else if (displayed <= 0)
            out.write("<div class=\"statusnotes\"><b>" + _t("none") + "</b></div>\n");
        out.write("<div class=\"statusnotes\"><b>" + _t("Lifetime bandwidth usage") + ":&nbsp;&nbsp;" + DataHelper.formatSize2Decimal(processed * 1024) + "B</b></div>\n");
    } else {
        out.write("<div class=\"statusnotes noparticipate\"><b>" + _t("Not enough shared bandwidth to build participating tunnels.") + "</b> <a href=\"config\">[" + _t("Configure") + "]</a></div>\n");
    }
    // renderPeers(out);
    out.write("<h3 class=\"tabletitle\">" + _t("Bandwidth Tiers") + "</h3>\n");
    out.write("<table id=\"tunnel_defs\"><tbody>");
    out.write("<tr><td>&nbsp;</td>" + "<td><span class=\"tunnel_cap\"><b>L</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_L, Router.MIN_BW_M)) + "</td>" + "<td><span class=\"tunnel_cap\"><b>M</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_M, Router.MIN_BW_N)) + "</td>" + "<td>&nbsp;</td></tr>");
    out.write("<tr><td>&nbsp;</td>" + "<td><span class=\"tunnel_cap\"><b>N</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_N, Router.MIN_BW_O)) + "</td>" + "<td><span class=\"tunnel_cap\"><b>O</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_O, Router.MIN_BW_P)) + "</td>" + "<td>&nbsp;</td></tr>");
    out.write("<tr><td>&nbsp;</td>" + "<td><span class=\"tunnel_cap\"><b>P</b></span></td><td>" + _t("{0} shared bandwidth", range(Router.MIN_BW_P, Router.MIN_BW_X)) + "</td>" + "<td><span class=\"tunnel_cap\"><b>X</b></span></td><td>" + _t("Over {0} shared bandwidth", Math.round(Router.MIN_BW_X * 1.024f) + " KBps") + "</td>" + "<td>&nbsp;</td></tr>");
    out.write("</tbody></table>");
}
Also used : TunnelPool(net.i2p.router.tunnel.pool.TunnelPool) HopConfig(net.i2p.router.tunnel.HopConfig) Hash(net.i2p.data.Hash) RateStat(net.i2p.stat.RateStat)

Example 25 with RateStat

use of net.i2p.stat.RateStat in project i2p.i2p by i2p.

the class Router method get1mRateIn.

/**
 *  Inbound rate in bytes per second
 */
public int get1mRateIn() {
    StatManager mgr = _context.statManager();
    RateStat rs = mgr.getRate("bw.recvRate");
    int recv = 0;
    if (rs != null)
        recv = (int) rs.getRate(1 * 60 * 1000).getAverageValue();
    return recv;
}
Also used : RateStat(net.i2p.stat.RateStat) StatManager(net.i2p.stat.StatManager)

Aggregations

RateStat (net.i2p.stat.RateStat)33 Rate (net.i2p.stat.Rate)24 Hash (net.i2p.data.Hash)5 RouterInfo (net.i2p.data.router.RouterInfo)5 RateAverages (net.i2p.stat.RateAverages)4 PeerProfile (net.i2p.router.peermanager.PeerProfile)3 ArrayList (java.util.ArrayList)2 RouterContext (net.i2p.router.RouterContext)2 StatManager (net.i2p.stat.StatManager)2 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1 RouterAddress (net.i2p.data.router.RouterAddress)1 CommSystemFacade (net.i2p.router.CommSystemFacade)1 TunnelInfo (net.i2p.router.TunnelInfo)1 DBHistory (net.i2p.router.peermanager.DBHistory)1 HopConfig (net.i2p.router.tunnel.HopConfig)1 TunnelPool (net.i2p.router.tunnel.pool.TunnelPool)1