Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get monitor up to speed again #3633

Merged
merged 6 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions monitor/src/main/java/bisq/monitor/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private void start() throws Throwable {
Capability.BLIND_VOTE,
Capability.DAO_STATE,
Capability.BUNDLE_OF_ENVELOPES,
Capability.REFUND_AGENT,
Capability.MEDIATION);

// assemble Metrics
Expand Down
2 changes: 1 addition & 1 deletion monitor/src/main/java/bisq/monitor/ThreadGate.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void engage(int numberOfLocks) {
public synchronized void await() {
while (lock.getCount() > 0)
try {
if (!lock.await(90, TimeUnit.SECONDS)) {
if (!lock.await(60, TimeUnit.SECONDS)) {
log.warn("timeout occured!");
break; // break the loop
}
Expand Down
4 changes: 3 additions & 1 deletion monitor/src/main/java/bisq/monitor/metric/MarketStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ protected void execute() {
// prepare to receive data
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

String all = in.readLine();
String line, all = "";
while ((line = in.readLine()) != null)
all += ' ' + line;
in.close();

Arrays.stream(all.substring(0, all.length() - 2).split("}")).forEach(trade -> {
Expand Down
128 changes: 69 additions & 59 deletions monitor/src/main/java/bisq/monitor/metric/PriceNodeStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.PrintWriter;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -81,72 +82,81 @@ protected void execute() {
checkNotNull(tor, "tor must not be null");
Socks5Proxy proxy = tor.getProxy();

String[] hosts = configuration.getProperty(HOSTS, "").split(",");

Collections.shuffle(Arrays.asList(hosts));

// for each configured host
for (String current : configuration.getProperty(HOSTS, "").split(",")) {
for (String current : hosts) {
Map<String, String> result = new HashMap<>();
// parse Url
NodeAddress tmp = OnionParser.getNodeAddress(current);

// connect
SocksSocket socket = new SocksSocket(proxy, tmp.getHostName(), tmp.getPort());

// prepare to receive data
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// ask for fee data
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
out.println("GET /getFees/");
out.println();
out.flush();

// sift through the received lines and see if we got something json-like
String line;
while((line = in.readLine()) != null) {
Matcher matcher = stringNumberPattern.matcher(line);
if(matcher.find())
if(!IGNORE.contains(matcher.group(1)))
result.put("fees." + matcher.group(1), matcher.group(2));
try {
SocksSocket socket = new SocksSocket(proxy, tmp.getHostName(), tmp.getPort());

// prepare to receive data
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// ask for fee data
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
out.println("GET /getFees/");
out.println();
out.flush();

// sift through the received lines and see if we got something json-like
String line;
while ((line = in.readLine()) != null) {
Matcher matcher = stringNumberPattern.matcher(line);
if (matcher.find())
if (!IGNORE.contains(matcher.group(1)))
result.put("fees." + matcher.group(1), matcher.group(2));
}

in.close();
out.close();
socket.close();

// connect
socket = new SocksSocket(proxy, tmp.getHostName(), tmp.getPort());

// prepare to receive data
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// ask for exchange rate data
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
out.println("GET /getAllMarketPrices/");
out.println();
out.flush();

String currencyCode = "";
while ((line = in.readLine()) != null) {
Matcher currencyCodeMatcher = currencyCodePattern.matcher(line);
Matcher priceMatcher = pricePattern.matcher(line);
if (currencyCodeMatcher.find()) {
currencyCode = currencyCodeMatcher.group(1);
if (!assets.contains(currencyCode))
currencyCode = "";
} else if (!"".equals(currencyCode) && priceMatcher.find())
result.put("price." + currencyCode, priceMatcher.group(1));
}

// close all the things
in.close();
out.close();
socket.close();

// report
reporter.report(result, getName());

// only ask for data as long as we got none
if (!result.isEmpty())
break;
} catch (IOException e) {
log.error("{} seems to be down. Trying next configured price node.", tmp.getHostName());
e.printStackTrace();
}

in.close();
out.close();
socket.close();

// connect
socket = new SocksSocket(proxy, tmp.getHostName(), tmp.getPort());

// prepare to receive data
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

// ask for exchange rate data
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
out.println("GET /getAllMarketPrices/");
out.println();
out.flush();

String currencyCode = "";
while((line = in.readLine()) != null) {
Matcher currencyCodeMatcher = currencyCodePattern.matcher(line);
Matcher priceMatcher = pricePattern.matcher(line);
if(currencyCodeMatcher.find()) {
currencyCode = currencyCodeMatcher.group(1);
if(!assets.contains(currencyCode))
currencyCode = "";
} else if(!"".equals(currencyCode) && priceMatcher.find())
result.put("price." + currencyCode, priceMatcher.group(1));
}

// close all the things
in.close();
out.close();
socket.close();

// report
reporter.report(result, getName());

// only ask for data as long as we got none
if(!result.isEmpty())
break;
}
} catch (TorCtlException | IOException e) {
// TODO Auto-generated catch block
Expand Down
2 changes: 1 addition & 1 deletion monitor/src/main/resources/metrics.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ P2PMarketStats.run.torProxyPort=9063
#PriceNodeStats Metric
PriceNodeStats.enabled=false
PriceNodeStats.run.interval=42
PriceNodeStats.run.hosts=http://5bmpx76qllutpcyp.onion, http://xc3nh4juf2hshy7e.onion, http://44mgyoe2b6oqiytt.onion, http://62nvujg5iou3vu3i.onion, http://ceaanhbvluug4we6.onion
PriceNodeStats.run.hosts=http://xc3nh4juf2hshy7e.onion, http://44mgyoe2b6oqiytt.onion, http://62nvujg5iou3vu3i.onion, http://ceaanhbvluug4we6.onion, http://gztmprecgqjq64zh.onion/

#MarketStats Metric
MarketStats.enabled=false
Expand Down