Search in sources :

Example 6 with Rate

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

the class ConfigStatsHelper method hasMoreStats.

/**
 * move the cursor to the next known stat, returning true if a valid
 * stat is available.
 *
 * @return true if a valid stat is available, otherwise false
 */
public boolean hasMoreStats() {
    if (_stats.isEmpty())
        return false;
    _currentIsGraphed = false;
    _currentStatName = _stats.remove(0);
    RateStat rs = _context.statManager().getRate(_currentStatName);
    if (rs != null) {
        _currentStatDescription = rs.getDescription();
        if (_currentGroup == null)
            _currentIsFirstInGroup = true;
        else if (!rs.getGroupName().equals(_currentGroup))
            _currentIsFirstInGroup = true;
        else
            _currentIsFirstInGroup = false;
        _currentGroup = rs.getGroupName();
        // should be the minimum
        long period = rs.getPeriods()[0];
        if (period <= 10 * 60 * 1000) {
            Rate r = rs.getRate(period);
            _currentCanBeGraphed = r != null;
            if (_currentCanBeGraphed) {
                // see above
                // _currentIsGraphed = r.getSummaryListener() != null;
                _currentGraphName = _currentStatName + "." + period;
                _currentIsGraphed = _graphs.contains(_currentGraphName);
            }
        } else {
            _currentCanBeGraphed = false;
        }
    } else {
        FrequencyStat fs = _context.statManager().getFrequency(_currentStatName);
        if (fs != null) {
            _currentStatDescription = fs.getDescription();
            if (_currentGroup == null)
                _currentIsFirstInGroup = true;
            else if (!fs.getGroupName().equals(_currentGroup))
                _currentIsFirstInGroup = true;
            else
                _currentIsFirstInGroup = false;
            _currentGroup = fs.getGroupName();
            _currentCanBeGraphed = false;
        } else {
            if (_log.shouldLog(Log.ERROR))
                _log.error("Stat does not exist?!  [" + _currentStatName + "]");
            return false;
        }
    }
    if (_filters.contains("*") || _filters.contains(_currentStatName))
        _currentIsLogged = true;
    else
        _currentIsLogged = false;
    return true;
}
Also used : FrequencyStat(net.i2p.stat.FrequencyStat) RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 7 with Rate

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

the class ExploratoryPeerSelector method getEvents.

/**
 * Use current + last to get more recent and smoother data
 */
private int getEvents(String stat, long period) {
    RateStat rs = ctx.statManager().getRate(stat);
    if (rs == null)
        return 0;
    Rate r = rs.getRate(period);
    if (r == null)
        return 0;
    return (int) (r.computeAverages().getTotalEventCount());
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 8 with Rate

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

the class StatisticsManager method includeAverageThroughput.

/* report the same data for tx and rx, for enhanced anonymity */
private void includeAverageThroughput(Properties stats) {
    RateStat sendRate = _context.statManager().getRate("bw.sendRate");
    RateStat recvRate = _context.statManager().getRate("bw.recvRate");
    if (sendRate == null || recvRate == null)
        return;
    Rate s = sendRate.getRate(60 * 60 * 1000);
    Rate r = recvRate.getRate(60 * 60 * 1000);
    if (s == null || r == null)
        return;
    double speed = (s.getAverageValue() + r.getAverageValue()) / 2;
    double max = Math.max(s.getExtremeAverageValue(), r.getExtremeAverageValue());
    String str = num(speed) + ';' + num(max) + ";0;0;";
    stats.setProperty("stat_bandwidthSendBps.60m", str);
    stats.setProperty("stat_bandwidthReceiveBps.60m", str);
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 9 with Rate

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

the class ProfileOrganizer method peerSendsBadReplies.

/**
 * Does the given peer send us bad replies - either invalid store messages
 * (expired, corrupt, etc) or unreachable replies (pointing towards routers
 * that don't exist).
 */
public boolean peerSendsBadReplies(Hash peer) {
    PeerProfile profile = getProfile(peer);
    if (profile != null && profile.getIsExpandedDB()) {
        RateStat invalidReplyRateStat = profile.getDBHistory().getInvalidReplyRate();
        Rate invalidReplyRate = invalidReplyRateStat.getRate(30 * 60 * 1000l);
        if ((invalidReplyRate.getCurrentTotalValue() > MAX_BAD_REPLIES_PER_HOUR) || (invalidReplyRate.getLastTotalValue() > MAX_BAD_REPLIES_PER_HOUR)) {
            return true;
        }
    }
    return false;
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Example 10 with Rate

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

the class RouterWatchdog method monitorRouter.

public void monitorRouter() {
    boolean ok = verifyJobQueueLiveliness();
    // If we aren't connected to the network that's why there's nobody to talk to
    long netErrors = 0;
    if (_context.commSystem().getStatus() == Status.DISCONNECTED) {
        netErrors = 10;
    } else {
        RateStat rs = _context.statManager().getRate("udp.sendException");
        if (rs != null) {
            Rate r = rs.getRate(60 * 1000);
            if (r != null)
                netErrors = r.getLastEventCount();
        }
    }
    ok = ok && (verifyClientLiveliness() || netErrors >= 5);
    if (ok) {
        _consecutiveErrors = 0;
    } else {
        _consecutiveErrors++;
        dumpStatus();
        if (shutdownOnHang()) {
            _log.log(Log.CRIT, "Router hung!  Restart forced by watchdog!");
            try {
                Thread.sleep(30 * 1000);
            } catch (InterruptedException ie) {
            }
            // halt and not system.exit, since some of the shutdown hooks might be misbehaving
            Runtime.getRuntime().halt(Router.EXIT_HARD_RESTART);
        }
    }
}
Also used : RateStat(net.i2p.stat.RateStat) Rate(net.i2p.stat.Rate)

Aggregations

Rate (net.i2p.stat.Rate)29 RateStat (net.i2p.stat.RateStat)24 RateAverages (net.i2p.stat.RateAverages)6 Hash (net.i2p.data.Hash)5 RouterInfo (net.i2p.data.router.RouterInfo)5 PeerProfile (net.i2p.router.peermanager.PeerProfile)4 TreeSet (java.util.TreeSet)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DBHistory (net.i2p.router.peermanager.DBHistory)2 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 RouterAddress (net.i2p.data.router.RouterAddress)1 CommSystemFacade (net.i2p.router.CommSystemFacade)1 RouterContext (net.i2p.router.RouterContext)1 TunnelInfo (net.i2p.router.TunnelInfo)1 MaskedIPSet (net.i2p.router.util.MaskedIPSet)1 SummaryListener (net.i2p.router.web.SummaryListener)1 FrequencyStat (net.i2p.stat.FrequencyStat)1 ConvertToHash (net.i2p.util.ConvertToHash)1