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

Bisq Network Monitor: Babysteps #2181

Merged
merged 45 commits into from Dec 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
df5b2dc
Basic framework for Monitor
freimair Dec 10, 2018
86d6425
Basic configuration infrastructure available
freimair Dec 10, 2018
984aabf
Periodical schedule
freimair Dec 10, 2018
52c5a7e
Use configurable properties file
freimair Dec 10, 2018
4796f1b
Reloading config during runtime available
freimair Dec 10, 2018
da483a2
Metrics can be disabled via config
freimair Dec 10, 2018
4d39d6b
Basic configuration tests
freimair Dec 10, 2018
a73c24f
Metrics can be reenabled via config
freimair Dec 10, 2018
930cb8c
Metrics can be renamed
freimair Dec 11, 2018
bb26694
Use lombok/slf4j for logging
freimair Dec 11, 2018
6481543
Configure gradle properly
freimair Dec 11, 2018
414623b
Introduce general purpose Tor instance
freimair Dec 18, 2018
0f8c420
Synchronize all the things
freimair Dec 18, 2018
9394da1
Introduce reporting stub
freimair Dec 18, 2018
677ed23
Add initial TorStartupTime metric
freimair Dec 18, 2018
1d6e101
Enhance config file documentation
freimair Dec 18, 2018
6b43b47
Cleanup
freimair Dec 18, 2018
4d0a094
Configurable socksPort for TorStartupTime Metric
freimair Dec 18, 2018
fb9c11f
TorRoundTripTime Metric available
freimair Dec 18, 2018
612c5f3
Refactored Metrics scheduler
freimair Dec 19, 2018
bff347b
TorRoundtripTime Metric does samples
freimair Dec 19, 2018
295cb6c
Graceful shutdown, Netlayer 0.6.2
freimair Dec 21, 2018
d46813c
TorHiddenServiceStartupTime Metric available
freimair Dec 18, 2018
2db74a1
Refactored TorStartupTime
freimair Dec 21, 2018
973bcf5
Introduce reporter concept
freimair Dec 28, 2018
09e02ba
Refactored Metric
freimair Dec 28, 2018
a7d86f3
Refactored metric infrastructure
freimair Dec 28, 2018
26f6088
Graphite reporter is available
freimair Dec 28, 2018
ada2e58
Pretty up config file
freimair Dec 28, 2018
7cf083b
Readme, Javadoc, cleanup
freimair Dec 29, 2018
59e5285
Dependencies and Buildfile cleanup
freimair Dec 29, 2018
f329370
Fixed compiation error as in: Commit of shame
freimair Dec 29, 2018
d4db4d8
Reformat code, organize imports, fix spelling
ManfredKarrer Dec 29, 2018
2762d74
Rename TorRoundtripTime to TorRoundTripTime
ManfredKarrer Dec 29, 2018
2d8ca8c
Add monitor directory as parent for test directories
ManfredKarrer Dec 29, 2018
cb533f4
Update gitignore
ManfredKarrer Dec 29, 2018
3661218
Removed unused dummy Metric
freimair Dec 29, 2018
1c58d89
Apply code inspection
ManfredKarrer Dec 29, 2018
69b168e
Add guava
ManfredKarrer Dec 29, 2018
579d1f1
Use 1.1.10 instead of $logbackVersion
ManfredKarrer Dec 29, 2018
e39f91a
Update hashes
ManfredKarrer Dec 29, 2018
b18c0b0
Ignore tests
ManfredKarrer Dec 29, 2018
cfec714
Merge branch 'master' into monitor
freimair Dec 30, 2018
decd648
Merge branch 'monitor-nits' of git://github.com/ManfredKarrer/bisq in…
freimair Dec 30, 2018
32650f1
Merge branch 'ManfredKarrer-monitor-nits' into monitor
freimair Dec 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions monitor/README.md
@@ -0,0 +1,57 @@
# Bisq Network Monitor Node

The Bisq monitor node collects a set of metrics which are of interest to developers and users alike. These metrics are then made available through reporters.

The *Babysteps* release features these metrics:
- Tor Startup Time: The time it takes to start Tor starting at a clean system, unpacking the shipped Tor binaries, firing up Tor until Tor is connected to the Tor network and ready to use.
- Tor Roundtrip Time: Given a bootstrapped Tor, the roundtrip time of connecting to a hidden service is measured.
- Tor Hidden Service Startup Time: Given a bootstrapped Tor, the time it takes to create and announce a freshly created hidden service.

The *Babysteps* release features these reporters:
- A reporter that simply writes the findings to `System.err`
- A reporter that reports the findings to a Graphite/Carbon instance using the [plaintext protocol](https://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol)

## Configuration

The *Bisq Network Monitor Node* is to be configured via a Java properties file. The location of the file is to be passed as command line parameter:

```
./bisq-monitor /path/to/your/config.properties
```

A sample configuration file looks like follows:

```
## Each Metric is configured via a set of properties.
##
## The minimal set of properties required to run a Metric is:
##
## YourMetricName.enabled=true|false
## YourMetricName.run.interval=10 [seconds]

#Edit and uncomment the lines below for your liking

#TorStartupTime Metric
TorStartupTime.enabled=true
TorStartupTime.run.interval=100
TorStartupTime.run.socksPort=90500 # so that there is no interference with a system Tor

#TorRoundtripTime Metric
TorRoundtripTime.enabled=true
TorRoundtripTime.run.interval=100
TorRoundtripTime.run.sampleSize=5
TorRoundtripTime.run.hosts=http://expyuzz4wqqyqhjn.onion:80 # torproject.org hidden service

#TorHiddenServiceStartupTime Metric
TorHiddenServiceStartupTime.enabled=true
TorHiddenServiceStartupTime.run.interval=100
TorHiddenServiceStartupTime.run.localPort=90501 # so that there is no interference with a system Tor
TorHiddenServiceStartupTime.run.servicePort=90511 # so that there is no interference with a system Tor

## Reporters are configured via a set of properties as well.
##
## In contrast to Metrics, Reporters do not have a minimal set of properties.

#GraphiteReporter
GraphiteReporter.serviceUrl=http://yourHiddenService.onion:2003
```
24 changes: 20 additions & 4 deletions monitor/src/main/java/bisq/monitor/Configurable.java
Expand Up @@ -20,20 +20,30 @@
import java.util.Properties;

/**
* Configurable is configurable.
* Does some precomputation for a configurable class.
*
* @author Florian Reimair
*/
freimair marked this conversation as resolved.
Show resolved Hide resolved
public abstract class Configurable {

protected Properties configuration = new Properties();

freimair marked this conversation as resolved.
Show resolved Hide resolved
protected Properties configuration;
private String name;

/**
* Configure the Configurable.
* Filters all java properties starting with {@link Configurable#getName()} of
* the class and makes them available. Does <em>NOT</em> parse the content of
* the properties!
* <p>
* For example, if the implementing class sets its name (using
* {@link Configurable#setName(String)}) to <code>MyName</code>, the list of
* properties is scanned for properties starting with <code>MyName</code>.
* Matching lines are made available to the class without the prefix. For
* example, a property <code>MyName.answer=42</code> is made available as
* <code>configuration.getProperty("answer")</code> resulting in
* <code>42</code>.
*
* @param properties
* @param properties a set of configuration properties
*/
public void configure(final Properties properties) {
// only configure the Properties which belong to us
Expand All @@ -52,6 +62,12 @@ protected String getName() {
return name;
}

/**
* Set the name used to filter through configuration properties. See
* {@link Configurable#configure(Properties)}.
*
* @param name
*/
protected void setName(String name) {
this.name = name;
}
Expand Down
12 changes: 6 additions & 6 deletions monitor/src/main/java/bisq/monitor/Metric.java
Expand Up @@ -22,7 +22,10 @@
import lombok.extern.slf4j.Slf4j;

/**
* Metric base class.
* Starts a Metric (in its own {@link Thread}), manages its properties and shuts
* it down gracefully. Furthermore, configuration updates and execution are done
* in a thread-save manner. Implementing classes only have to implement the
* {@link Metric#execute()} method.
*
* @author Florian Reimair
*/
Expand Down Expand Up @@ -79,11 +82,7 @@ protected boolean enabled() {
return !shutdown;
}

/**
* Configures the Metric.
*
* @param properties
*/
@Override
public void configure(final Properties properties) {
synchronized (this) {
log.info("{} (re)loading config...", getName());
Expand Down Expand Up @@ -113,6 +112,7 @@ else if (!configuration.containsKey(INTERVAL))
}
}

@Override
public void run() {
while (!shutdown) {
// if not, execute all the things
Expand Down
7 changes: 3 additions & 4 deletions monitor/src/main/java/bisq/monitor/Monitor.java
Expand Up @@ -65,7 +65,7 @@ private void start() throws Throwable {

// assemble Metrics
// - create reporters
ConsoleReporter consoleReporter = new ConsoleReporter();
// ConsoleReporter consoleReporter = new ConsoleReporter();
Reporter graphiteReporter = new GraphiteReporter();

// - add available metrics with their reporters
Expand All @@ -89,6 +89,7 @@ private void start() throws Throwable {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
// set the name of the Thread for debugging purposes
setName("shutdownHook");

for (Metric current : metrics) {
Expand All @@ -99,9 +100,7 @@ public void run() {
for (Metric current : metrics)
try {
current.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException ignore) {
}

log.info("shutting down tor");
Expand Down
Expand Up @@ -17,7 +17,6 @@

package bisq.monitor;


import java.util.HashMap;
import java.util.Properties;

Expand Down Expand Up @@ -47,7 +46,6 @@ public boolean active() {
protected void execute() {
// do nothing
}

}

@ParameterizedTest
Expand Down
Expand Up @@ -17,7 +17,6 @@

package bisq.monitor;


import java.io.File;
import java.util.Map;
import java.util.Properties;
Expand All @@ -34,14 +33,18 @@

public class TorHiddenServiceStartupTimeTests {

private final static File torWorkingDirectory = new File(TorHiddenServiceStartupTimeTests.class.getSimpleName());

/**
* A dummy Reporter for development purposes.
*/
private class DummyReporter extends Reporter {

private long result;

@Override
public void report(long value) {
result = value;

}

public long results() {
Expand All @@ -62,19 +65,16 @@ public void report(Map<String, String> values, String prefix) {
public void report(long value, String prefix) {
report(value);
}

}

private final static File torWorkingDirectory = new File(TorHiddenServiceStartupTimeTests.class.getSimpleName());

@BeforeAll
public static void setup() throws TorCtlException {
// simulate the tor instance available to all metrics
Tor.setDefault(new NativeTor(torWorkingDirectory));
}

@Test
public void run() throws Exception {

DummyReporter reporter = new DummyReporter();

// configure
Expand Down
13 changes: 9 additions & 4 deletions monitor/src/test/java/bisq/monitor/TorRoundtripTimeTests.java
Expand Up @@ -17,9 +17,7 @@

package bisq.monitor;


import java.io.File;
import java.lang.Thread.State;
import java.util.Map;
import java.util.Properties;

Expand All @@ -34,8 +32,16 @@

import bisq.monitor.metric.TorRoundtripTime;

/**
* Test the roundtrip time metric against the hidden service of torproject.org.
*
* @author Florian Reimair
*/
public class TorRoundtripTimeTests {

/**
* A dummy Reporter for development purposes.
*/
private class DummyReporter extends Reporter {

private Map<String, String> results;
Expand Down Expand Up @@ -63,20 +69,19 @@ public void report(Map<String, String> values, String prefix) {
public void report(long value, String prefix) {
report(value);
}

}

private static File workingDirectory = new File(TorRoundtripTimeTests.class.getSimpleName());

@BeforeAll
public static void setup() throws TorCtlException {
// simulate the tor instance available to all metrics
Tor.setDefault(new NativeTor(workingDirectory));
}

@ParameterizedTest
@ValueSource(strings = { "default", "3", "4", "10" })
public void run(String sampleSize) throws Exception {

DummyReporter reporter = new DummyReporter();

// configure
Expand Down
7 changes: 4 additions & 3 deletions monitor/src/test/java/bisq/monitor/TorStartupTimeTests.java
Expand Up @@ -17,7 +17,6 @@

package bisq.monitor;


import java.util.Map;
import java.util.Properties;

Expand All @@ -28,15 +27,18 @@

public class TorStartupTimeTests {

/**
* A dummy Reporter for development purposes.
*/
private class DummyReporter extends Reporter {

private long result;

@Override
public void report(long value) {
result = value;

}

public long results() {
return result;
}
Expand All @@ -54,7 +56,6 @@ public void report(Map<String, String> values, String prefix) {
@Override
public void report(long value, String prefix) {
report(value);

}
}

Expand Down