-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2348 from freimair/monitor
Monitor release: Showing off
- Loading branch information
Showing
17 changed files
with
1,295 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.monitor; | ||
|
||
import java.io.File; | ||
import org.berndpruenster.netlayer.tor.Tor; | ||
import bisq.network.p2p.network.TorMode; | ||
|
||
/** | ||
* This class uses an already defined Tor via <code>Tor.getDefault()</code> | ||
* | ||
* @author Florian Reimair | ||
* | ||
*/ | ||
public class AvailableTor extends TorMode { | ||
|
||
private String hiddenServiceDirectory; | ||
|
||
public AvailableTor(File torWorkingDirectory, String hiddenServiceDirectory) { | ||
super(torWorkingDirectory); | ||
|
||
this.hiddenServiceDirectory = hiddenServiceDirectory; | ||
} | ||
|
||
@Override | ||
public Tor getTor() { | ||
return Tor.getDefault(); | ||
} | ||
|
||
@Override | ||
public String getHiddenServiceDirectory() { | ||
return hiddenServiceDirectory; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.monitor; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import bisq.network.p2p.NodeAddress; | ||
|
||
/** | ||
* Helper for parsing and pretty printing onion addresses. | ||
* | ||
* @author Florian Reimair | ||
*/ | ||
public class OnionParser { | ||
|
||
public static NodeAddress getNodeAddress(final String current) throws MalformedURLException { | ||
String nodeAddress = current.trim(); | ||
if (!nodeAddress.startsWith("http://")) | ||
nodeAddress = "http://" + nodeAddress; | ||
URL tmp = new URL(nodeAddress); | ||
return new NodeAddress(tmp.getHost(), tmp.getPort()); | ||
} | ||
|
||
public static String prettyPrint(final NodeAddress host) { | ||
return host.getHostNameWithoutPostFix(); | ||
} | ||
|
||
public static String prettyPrint(String host) throws MalformedURLException { | ||
return prettyPrint(getNodeAddress(host)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.monitor; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.LongSummaryStatistics; | ||
import java.util.Map; | ||
|
||
/** | ||
* Calculates average, max, min, p25, p50, p75 off of a list of samples and | ||
* throws in the sample size for good measure. | ||
* | ||
* @author Florian Reimair | ||
*/ | ||
public class StatisticsHelper { | ||
|
||
public static Map<String, String> process(List<Long> samples) { | ||
|
||
// aftermath | ||
Collections.sort(samples); | ||
|
||
// - average, max, min , sample size | ||
LongSummaryStatistics statistics = samples.stream().mapToLong(val -> val).summaryStatistics(); | ||
|
||
Map<String, String> results = new HashMap<>(); | ||
results.put("average", String.valueOf(Math.round(statistics.getAverage()))); | ||
results.put("max", String.valueOf(statistics.getMax())); | ||
results.put("min", String.valueOf(statistics.getMin())); | ||
results.put("sampleSize", String.valueOf(statistics.getCount())); | ||
|
||
// - p25, median, p75 | ||
Integer[] percentiles = new Integer[] { 25, 50, 75 }; | ||
for (Integer percentile : percentiles) { | ||
double rank = statistics.getCount() * percentile / 100; | ||
Long percentileValue; | ||
if (samples.size() <= rank + 1) | ||
percentileValue = samples.get(samples.size() - 1); | ||
else if (Math.floor(rank) == rank) | ||
percentileValue = samples.get((int) rank); | ||
else | ||
percentileValue = Math.round(samples.get((int) Math.floor(rank)) | ||
+ (samples.get((int) (Math.floor(rank) + 1)) - samples.get((int) Math.floor(rank))) | ||
/ (rank - Math.floor(rank))); | ||
results.put("p" + percentile, String.valueOf(percentileValue)); | ||
} | ||
|
||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.monitor; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Gate pattern to help with thread synchronization | ||
* | ||
* @author Florian Reimair | ||
*/ | ||
@Slf4j | ||
public class ThreadGate { | ||
|
||
private CountDownLatch lock = new CountDownLatch(0); | ||
|
||
/** | ||
* Make everyone wait until the gate is open again. | ||
*/ | ||
public void engage() { | ||
lock = new CountDownLatch(1); | ||
} | ||
|
||
/** | ||
* Make everyone wait until the gate is open again. | ||
* | ||
* @param numberOfLocks how often the gate has to be unlocked until the gate | ||
* opens. | ||
*/ | ||
public void engage(int numberOfLocks) { | ||
lock = new CountDownLatch(numberOfLocks); | ||
} | ||
|
||
/** | ||
* Wait for the gate to be opened. Blocks until the gate is open again. Returns | ||
* immediately if the gate is already open. | ||
*/ | ||
public synchronized void await() { | ||
while (lock.getCount() > 0) | ||
try { | ||
if (!lock.await(90, TimeUnit.SECONDS)) { | ||
log.warn("timeout occured!"); | ||
break; // break the loop | ||
} | ||
} catch (InterruptedException ignore) { | ||
} | ||
} | ||
|
||
/** | ||
* Open the gate and let everyone proceed with their execution. | ||
*/ | ||
public void proceed() { | ||
lock.countDown(); | ||
} | ||
|
||
/** | ||
* Open the gate with no regards on how many locks are still in place. | ||
*/ | ||
public void unlock() { | ||
while (lock.getCount() > 0) | ||
lock.countDown(); | ||
} | ||
} |
Oops, something went wrong.