CoalesceStatsEvent: Add new known peers stat

cleanups
This commit is contained in:
zzz
2019-12-14 13:18:02 +00:00
parent 6197454225
commit a5efce883a

View File

@ -11,8 +11,10 @@ package net.i2p.router.tasks;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.router.Router; import net.i2p.router.Router;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.stat.Rate; import net.i2p.stat.Rate;
import net.i2p.stat.RateStat; import net.i2p.stat.RateStat;
import net.i2p.stat.StatManager;
import net.i2p.util.SimpleTimer; import net.i2p.util.SimpleTimer;
/** /**
@ -26,76 +28,79 @@ public class CoalesceStatsEvent implements SimpleTimer.TimedEvent {
private static final long LOW_MEMORY_THRESHOLD = 5 * 1024 * 1024; private static final long LOW_MEMORY_THRESHOLD = 5 * 1024 * 1024;
public CoalesceStatsEvent(RouterContext ctx) { public CoalesceStatsEvent(RouterContext ctx) {
_ctx = ctx; _ctx = ctx;
StatManager sm = ctx.statManager();
// NOTE TO TRANSLATORS - each of these phrases is a description for a statistic // NOTE TO TRANSLATORS - each of these phrases is a description for a statistic
// to be displayed on /stats.jsp and in the graphs on /graphs.jsp. // to be displayed on /stats.jsp and in the graphs on /graphs.jsp.
// Please keep relatively short so it will fit on the graphs. // Please keep relatively short so it will fit on the graphs.
ctx.statManager().createRequiredRateStat("bw.receiveBps", _x("Message receive rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000, 5*60*1000, 60*60*1000 }); sm.createRequiredRateStat("bw.receiveBps", _x("Message receive rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000, 5*60*1000, 60*60*1000 });
ctx.statManager().createRequiredRateStat("bw.sendBps", _x("Message send rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000, 5*60*1000, 60*60*1000 }); sm.createRequiredRateStat("bw.sendBps", _x("Message send rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000, 5*60*1000, 60*60*1000 });
ctx.statManager().createRequiredRateStat("bw.sendRate", _x("Low-level send rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000l, 5*60*1000l, 60*60*1000l }); sm.createRequiredRateStat("bw.sendRate", _x("Low-level send rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000l, 5*60*1000l, 60*60*1000l });
ctx.statManager().createRequiredRateStat("bw.recvRate", _x("Low-level receive rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000l, 5*60*1000l, 60*60*1000l }); sm.createRequiredRateStat("bw.recvRate", _x("Low-level receive rate (bytes/sec)"), "Bandwidth", new long[] { 60*1000l, 5*60*1000l, 60*60*1000l });
ctx.statManager().createRequiredRateStat("router.activePeers", _x("How many peers we are actively talking with"), "Throttle", new long[] { 60*1000 }); sm.createRequiredRateStat("router.activePeers", _x("How many peers we are actively talking with"), "Throttle", new long[] { 60*1000 });
ctx.statManager().createRequiredRateStat("router.highCapacityPeers", "How many high capacity peers we know", "Throttle", new long[] { 60*1000 }); sm.createRequiredRateStat("router.highCapacityPeers", "How many high capacity peers we know", "Throttle", new long[] { 60*1000 });
ctx.statManager().createRateStat("router.activeSendPeers", "How many peers we've sent to this minute", "Throttle", new long[] { 60*1000 }); sm.createRateStat("router.activeSendPeers", "How many peers we've sent to this minute", "Throttle", new long[] { 60*1000 });
ctx.statManager().createRequiredRateStat("router.fastPeers", _x("Known fast peers"), "Throttle", new long[] { 60*1000 }); sm.createRequiredRateStat("router.fastPeers", _x("Known fast peers"), "Throttle", new long[] { 60*1000 });
ctx.statManager().createRateStat("router.integratedPeers", _x("Known integrated (floodfill) peers"), "Throttle", new long[] { 60*1000 }); sm.createRateStat("router.integratedPeers", "Known integrated (floodfill) peers", "NetworkDatabase", new long[] { 60*1000 });
ctx.statManager().createRequiredRateStat("router.tunnelBacklog", _x("Size of tunnel acceptor backlog"), "Tunnels", new long[] { 60*60*1000 }); sm.createRateStat("router.knownPeers", "Known peers", "NetworkDatabase", new long[] { 60*1000 });
sm.createRequiredRateStat("router.tunnelBacklog", _x("Size of tunnel acceptor backlog"), "Tunnels", new long[] { 60*60*1000 });
_maxMemory = Runtime.getRuntime().maxMemory(); _maxMemory = Runtime.getRuntime().maxMemory();
String legend = "(Bytes)"; String legend = "(Bytes)";
if (_maxMemory < Long.MAX_VALUE) if (_maxMemory < Long.MAX_VALUE)
legend += " Max is " + DataHelper.formatSize(_maxMemory) + 'B'; legend += " Max is " + DataHelper.formatSize(_maxMemory) + 'B';
// router.memoryUsed currently has the max size in the description so it can't be tagged // router.memoryUsed currently has the max size in the description so it can't be tagged
ctx.statManager().createRequiredRateStat("router.memoryUsed", legend, "Router", new long[] { 60*1000 }); sm.createRequiredRateStat("router.memoryUsed", legend, "Router", new long[] { 60*1000 });
} }
private RouterContext getContext() { return _ctx; }
public void timeReached() { public void timeReached() {
int active = getContext().commSystem().countActivePeers(); StatManager sm = _ctx.statManager();
getContext().statManager().addRateData("router.activePeers", active, 60*1000); int active = _ctx.commSystem().countActivePeers();
sm.addRateData("router.activePeers", active);
int activeSend = getContext().commSystem().countActiveSendPeers(); int activeSend = _ctx.commSystem().countActiveSendPeers();
getContext().statManager().addRateData("router.activeSendPeers", activeSend, 60*1000); sm.addRateData("router.activeSendPeers", activeSend);
int fast = getContext().profileOrganizer().countFastPeers(); int fast = _ctx.profileOrganizer().countFastPeers();
getContext().statManager().addRateData("router.fastPeers", fast, 60*1000); sm.addRateData("router.fastPeers", fast);
int highCap = getContext().profileOrganizer().countHighCapacityPeers(); int highCap = _ctx.profileOrganizer().countHighCapacityPeers();
getContext().statManager().addRateData("router.highCapacityPeers", highCap, 60*1000); sm.addRateData("router.highCapacityPeers", highCap);
int integrated = getContext().peerManager().getPeersByCapability('f').size(); int integrated = _ctx.peerManager().countPeersByCapability(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL);
getContext().statManager().addRateData("router.integratedPeers", integrated, 60*1000); sm.addRateData("router.integratedPeers", integrated);
getContext().statManager().addRateData("bw.sendRate", (long)getContext().bandwidthLimiter().getSendBps()); sm.addRateData("router.knownPeers", _ctx.netDb().getKnownRouters());
getContext().statManager().addRateData("bw.recvRate", (long)getContext().bandwidthLimiter().getReceiveBps());
sm.addRateData("bw.sendRate", (long)_ctx.bandwidthLimiter().getSendBps());
sm.addRateData("bw.recvRate", (long)_ctx.bandwidthLimiter().getReceiveBps());
getContext().statManager().addRateData("router.tunnelBacklog", getContext().tunnelManager().getInboundBuildQueueSize(), 60*1000); sm.addRateData("router.tunnelBacklog", _ctx.tunnelManager().getInboundBuildQueueSize());
long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
getContext().statManager().addRateData("router.memoryUsed", used); sm.addRateData("router.memoryUsed", used);
if (_maxMemory - used < LOW_MEMORY_THRESHOLD) if (_maxMemory - used < LOW_MEMORY_THRESHOLD)
Router.clearCaches(); Router.clearCaches();
getContext().tunnelDispatcher().updateParticipatingStats(Router.COALESCE_TIME); _ctx.tunnelDispatcher().updateParticipatingStats(Router.COALESCE_TIME);
getContext().statManager().coalesceStats(); sm.coalesceStats();
RateStat receiveRate = getContext().statManager().getRate("transport.receiveMessageSize"); RateStat receiveRate = sm.getRate("transport.receiveMessageSize");
if (receiveRate != null) { if (receiveRate != null) {
Rate rate = receiveRate.getRate(60*1000); Rate rate = receiveRate.getRate(60*1000);
if (rate != null) { if (rate != null) {
double bytes = rate.getLastTotalValue(); double bytes = rate.getLastTotalValue();
double bps = (bytes*1000.0d)/rate.getPeriod(); double bps = (bytes*1000.0d)/rate.getPeriod();
getContext().statManager().addRateData("bw.receiveBps", (long)bps, 60*1000); sm.addRateData("bw.receiveBps", (long)bps, 60*1000);
} }
} }
RateStat sendRate = getContext().statManager().getRate("transport.sendMessageSize"); RateStat sendRate = sm.getRate("transport.sendMessageSize");
if (sendRate != null) { if (sendRate != null) {
Rate rate = sendRate.getRate(60*1000); Rate rate = sendRate.getRate(60*1000);
if (rate != null) { if (rate != null) {
double bytes = rate.getLastTotalValue(); double bytes = rate.getLastTotalValue();
double bps = (bytes*1000.0d)/rate.getPeriod(); double bps = (bytes*1000.0d)/rate.getPeriod();
getContext().statManager().addRateData("bw.sendBps", (long)bps, 60*1000); sm.addRateData("bw.sendBps", (long)bps, 60*1000);
} }
} }
} }