Skip to content

Commit

Permalink
try to fix bug where network monitor will show speeds in EB/s which b…
Browse files Browse the repository at this point in the history
…reaks the graph.
  • Loading branch information
lamarios committed May 21, 2017
1 parent 6b58994 commit 823c46a
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Map<String, String> exposeSettings() {

@Override
protected Map<String, Object> getSettingsModel() {
return Stream.of(systemInfo.getHardware().getNetworkIFs()).collect(Collectors.toMap(NetworkIF::getName, netIf-> String.join(", ", netIf.getIPv4addr())));
return Stream.of(systemInfo.getHardware().getNetworkIFs()).collect(Collectors.toMap(NetworkIF::getName, netIf -> String.join(", ", netIf.getIPv4addr())));
}

//////// plugin methods
Expand All @@ -147,28 +147,32 @@ public NetworkInfo getNetworkInfo(String netInterface) {
if (!networkInfos.isEmpty()) { // we have data let's proceed to calculation
NetworkInfo old = networkInfos.get(networkInfos.size() - 1);

logger.info("[Network info] We have history, lets calculate the speed since last refresh");
long transferredUp = currentTotalUp - old.totalUp;
long transferredDown = currentTotalDown - old.totalDown;
double duration = (currentTime - old.time) / 1000; // from
// millisecond
// to seconds
logger.info("[Network info] Uploaded [{}] Downloaded [{}] in [{}]s", transferredUp, transferredDown, duration);
if (old.totalDown > 0 && old.totalUp > 0) {
logger.info("[Network info] We have history, lets calculate the speed since last refresh");
long transferredUp = currentTotalUp - old.totalUp;
long transferredDown = currentTotalDown - old.totalDown;
double duration = (currentTime - old.time) / 1000; // from
// millisecond
// to seconds
logger.info("[Network info] Uploaded [{}] Downloaded [{}] in [{}]s", transferredUp, transferredDown, duration);

networkInfo.down = (long) Math.ceil(transferredDown / duration);
networkInfo.up = (long) Math.ceil(transferredUp / duration);

networkInfo.readableDown = ByteUtils.humanReadableByteCount(networkInfo.down, true) + "/s";
networkInfo.readableUp = ByteUtils.humanReadableByteCount(networkInfo.up, true) + "/s";
}

networkInfo.down = (long) Math.ceil(transferredDown / duration);
networkInfo.up = (long) Math.ceil(transferredUp / duration);
networkInfo.time = currentTime;

}
networkInfo.time = currentTime;

networkInfo.totalDown = currentTotalDown;
networkInfo.totalUp = currentTotalUp;

networkInfo.readableTotalDown = ByteUtils.humanReadableByteCount(networkInfo.totalDown, true);
networkInfo.readableTotalUp = ByteUtils.humanReadableByteCount(networkInfo.totalUp, true);

networkInfo.readableDown = ByteUtils.humanReadableByteCount(networkInfo.down, true) + "/s";
networkInfo.readableUp = ByteUtils.humanReadableByteCount(networkInfo.up, true) + "/s";

return networkInfo;
} else {
Expand Down

0 comments on commit 823c46a

Please sign in to comment.