Normalize NetworkLoad data to messages per minute

This commit is contained in:
Florian Reimair 2019-02-12 18:50:16 +01:00
parent 315b79e3a5
commit 14c89f179c
No known key found for this signature in database
GPG Key ID: 7EA8CA324B6E5633

View File

@ -84,6 +84,7 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
* dropped to record newer hashes.
*/
private Map<Integer, Object> history;
private long lastRun = 0;
/**
* History implementation using a {@link LinkedHashMap} and its
@ -204,18 +205,25 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
// - get snapshot so we do not loose data
Set<String> keys = new HashSet<>(buckets.keySet());
if(lastRun != 0 && System.currentTimeMillis() - lastRun != 0) {
// - normalize to data/minute
double perMinuteFactor = 60000.0 / (System.currentTimeMillis() - lastRun);
// - transfer values to report
keys.forEach(key -> {
int value = buckets.get(key).getAndReset();
if(value != 0)
report.put(key, String.valueOf(value));
report.put(key, String.format("%.2f", value * perMinuteFactor));
});
// - report
reporter.report(report, "bisq." + getName());
}
// - reset last run
lastRun = System.currentTimeMillis();
}
@Override
public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
// TODO check if we already have this very message