Skip to content

Commit

Permalink
Merge pull request #4787 from chimp1984/various-monitor-improvements
Browse files Browse the repository at this point in the history
Various monitor improvements
  • Loading branch information
ripcurlx authored Nov 18, 2020
2 parents 29b2c33 + ccfcc35 commit 457257b
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 66 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/bisq/common/setup/CommonSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
public class CommonSetup {

public static void setup(Config config, GracefulShutDownHandler gracefulShutDownHandler) {
AsciiLogo.showAsciiLogo();
setupLog(config);
AsciiLogo.showAsciiLogo();
Version.setBaseCryptoNetworkId(config.baseCurrencyNetwork.ordinal());
Version.printVersion();
maybePrintPathOfCodeSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
inventory.put(InventoryItem.numConnections, String.valueOf(networkNode.getAllConnections().size()));
inventory.put(InventoryItem.peakNumConnections, String.valueOf(peerManager.getPeakNumConnections()));
inventory.put(InventoryItem.numAllConnectionsLostEvents, String.valueOf(peerManager.getNumAllConnectionsLostEvents()));
peerManager.resetNumAllConnectionsLostEvents();
peerManager.maybeResetNumAllConnectionsLostEvents();
inventory.put(InventoryItem.sentBytes, String.valueOf(Statistic.totalSentBytesProperty().get()));
inventory.put(InventoryItem.sentBytesPerSec, String.valueOf(Statistic.totalSentBytesPerSecProperty().get()));
inventory.put(InventoryItem.receivedBytes, String.valueOf(Statistic.totalReceivedBytesProperty().get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void request() {
}

private void onTimeOut() {
errorMessageHandler.handleErrorMessage("Timeout got triggered (" + TIMEOUT_SEC + " sec)");
errorMessageHandler.handleErrorMessage("Request timeout");
shutDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum InventoryItem {
// Percentage deviation
OfferPayload("OfferPayload",
true,
new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 5),
new DeviationByPercentage(0.8, 1.2, 0.9, 1.1), 5),
MailboxStoragePayload("MailboxStoragePayload",
true,
new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),
Expand Down Expand Up @@ -102,7 +102,7 @@ public enum InventoryItem {
new DeviationByPercentage(0, 3, 0, 2.5), 2),
numAllConnectionsLostEvents("numAllConnectionsLostEvents",
true,
new DeviationByIntegerDiff(1, 2), 3),
new DeviationByIntegerDiff(1, 2), 1),
sentBytesPerSec("sentBytesPerSec",
true,
new DeviationByPercentage(), 5),
Expand Down Expand Up @@ -137,6 +137,7 @@ public enum InventoryItem {

// The number of past requests we check to see if there have been repeated alerts or warnings. The higher the
// number the more repeated alert need to have happened to cause a notification alert.
// Smallest number is 1, as that takes only the last request data and does not look further back.
@Getter
private int deviationTolerance = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Getter
public class RequestInfo {
// Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field)
public static final String COMMIT_HASH = "d789282b";
public static final String COMMIT_HASH = "7f83d1b3";

private final long requestStartTime;
@Setter
Expand All @@ -56,6 +56,10 @@ public String getValue(InventoryItem inventoryItem) {
null;
}

public boolean hasError() {
return errorMessage != null && !errorMessage.isEmpty();
}

@Value
public static class Data {
private final String value;
Expand Down
47 changes: 26 additions & 21 deletions inventory/src/main/java/bisq/inventory/InventoryMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.inventory;


import bisq.core.app.TorSetup;
import bisq.core.network.p2p.inventory.GetInventoryRequestManager;
import bisq.core.network.p2p.inventory.model.Average;
import bisq.core.network.p2p.inventory.model.DeviationSeverity;
Expand Down Expand Up @@ -61,8 +62,8 @@ public class InventoryMonitor implements SetupListener {
private final File appDir;
private final boolean useLocalhostForP2P;
private final int intervalSec;
private final NetworkNode networkNode;
private final GetInventoryRequestManager getInventoryRequestManager;
private NetworkNode networkNode;
private GetInventoryRequestManager getInventoryRequestManager;

private ArrayList<NodeAddress> seedNodes;
private InventoryWebServer inventoryWebServer;
Expand All @@ -82,20 +83,25 @@ public InventoryMonitor(File appDir,
this.useLocalhostForP2P = useLocalhostForP2P;
this.intervalSec = intervalSec;

networkNode = getNetworkNode(appDir);
getInventoryRequestManager = new GetInventoryRequestManager(networkNode);

// We maintain our own list as we want to monitor also old v2 nodes which are not part of the normal seed
// node list anymore.
String networkName = network.name().toLowerCase();
String fileName = network.isMainnet() ? "inv_" + networkName : networkName;
DefaultSeedNodeRepository.readSeedNodePropertyFile(fileName)
.ifPresent(bufferedReader -> {
seedNodes = new ArrayList<>(DefaultSeedNodeRepository.getSeedNodeAddressesFromPropertyFile(fileName));
addJsonFileManagers(seedNodes);
inventoryWebServer = new InventoryWebServer(port, seedNodes, bufferedReader);
networkNode.start(this);
});
// We get more connectivity issues. Cleaning tor cache files helps usually for those problems.
File torDir = new File(appDir, "tor");
TorSetup torSetup = new TorSetup(torDir);
torSetup.cleanupTorFiles(() -> {
networkNode = getNetworkNode(torDir);
getInventoryRequestManager = new GetInventoryRequestManager(networkNode);

// We maintain our own list as we want to monitor also old v2 nodes which are not part of the normal seed
// node list anymore.
String networkName = network.name().toLowerCase();
String fileName = network.isMainnet() ? "inv_" + networkName : networkName;
DefaultSeedNodeRepository.readSeedNodePropertyFile(fileName)
.ifPresent(bufferedReader -> {
seedNodes = new ArrayList<>(DefaultSeedNodeRepository.getSeedNodeAddressesFromPropertyFile(fileName));
addJsonFileManagers(seedNodes);
inventoryWebServer = new InventoryWebServer(port, seedNodes, bufferedReader);
networkNode.start(this);
});
}, log::error);
}


Expand Down Expand Up @@ -154,16 +160,16 @@ private void processResponse(NodeAddress nodeAddress,
RequestInfo requestInfo,
@Nullable Map<InventoryItem, String> result,
@Nullable String errorMessage) {
if (errorMessage != null) {
if (errorMessage != null && !errorMessage.isEmpty()) {
log.warn("Error at connection to peer {}: {}", nodeAddress, errorMessage);
requestInfo.setErrorMessage(errorMessage);
} else {
requestInfo.setResponseTime(System.currentTimeMillis());
}

boolean ignoreDeviationAtStartup;
if (result != null) {
log.info("nodeAddress={}, result={}", nodeAddress, result.toString());
long responseTime = System.currentTimeMillis();
requestInfo.setResponseTime(responseTime);

// If seed just started up we ignore the deviation as it can be expected that seed is still syncing
// DAO state/blocks. P2P data should be ready but as we received it from other seeds it is not that
Expand Down Expand Up @@ -247,8 +253,7 @@ private void addJsonFileManagers(List<NodeAddress> seedNodes) {
});
}

private NetworkNode getNetworkNode(File appDir) {
File torDir = new File(appDir, "tor");
private NetworkNode getNetworkNode(File torDir) {
CoreNetworkProtoResolver networkProtoResolver = new CoreNetworkProtoResolver(Clock.systemDefaultZone());
return new NetworkNodeProvider(networkProtoResolver,
ArrayList::new,
Expand Down
Loading

0 comments on commit 457257b

Please sign in to comment.