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;
}
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());
}
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);
}
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;
}
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);
}
}
}
Aggregations