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 29 commits
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,34 @@ configure(project(':desktop')) {


configure(project(':monitor')) {
mainClassName = 'bisq.monitor.MonitorMain'
mainClassName = 'bisq.monitor.Monitor'

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}

dependencies {
compile project(':core')
compile "com.sparkjava:spark-core:$sparkVersion"
compile 'net.gpedro.integrations.slack:slack-webhook:1.1.1'
compile 'org.slf4j:slf4j-api:1.7.22'
compile 'ch.qos.logback:logback-core:1.1.10'
compile 'ch.qos.logback:logback-classic:1.1.10'
freimair marked this conversation as resolved.
Show resolved Hide resolved
compileOnly "org.projectlombok:lombok:$lombokVersion"
annotationProcessor "org.projectlombok:lombok:$lombokVersion"

compile('com.github.JesusMcCloud.netlayer:tor.native:0.6.2') {
exclude(module: 'slf4j-api')
}
compile('com.github.JesusMcCloud.netlayer:tor.external:0.6') {
exclude(module: 'slf4j-api')
}

testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.2'
testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.2'
testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.2')
}
}

Expand Down
69 changes: 0 additions & 69 deletions gradle/witness/gradle-witness.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,3 @@
// 4. Commit the changes
//
// See https://github.com/signalapp/gradle-witness#using-witness for further details.
dependencyVerification {
verify = [
'org.controlsfx:controlsfx:b98f1c9507c05600f80323674b33d15674926c71b0116f70085b62bdacf1e573',
'org.reactfx:reactfx:81ec8fe545d65661222735711114c2ce427e2187a65f1722e8ac4e4805beeca3',
'net.glxn:qrgen:c85d9d8512d91e8ad11fe56259a7825bd50ce0245447e236cf168d1b17591882',
'de.jensd:fontawesomefx:73bacc991a0a6f5cf0f911767c8db161e0949dbca61e8371eb4342e3da96887b',
'de.jensd:fontawesomefx-materialdesignfont:dbad8dfdd1c85e298d5bbae25b2399aec9e85064db57b2427d10f3815aa98752',
'de.jensd:fontawesomefx-commons:5539bb3335ecb822dbf928546f57766eeb9f1516cc1417a064b5709629612149',
'com.googlecode.jcsv:jcsv:73ca7d715e90c8d2c2635cc284543b038245a34f70790660ed590e157b8714a2',
'com.github.sarxos:webcam-capture:d960b7ea8ec3ddf2df0725ef214c3fccc9699ea7772df37f544e1f8e4fd665f6',
'com.jfoenix:jfoenix:4739e37a05e67c3bc9d5b391a1b93717b5a48fa872992616b0964d3f827f8fe6',
'com.github.JesusMcCloud.netlayer:tor.native:f1bf0096f9eb6020645a65d91aa530d15aef97e69cc5a79d7b2405421f74700a',
'com.github.JesusMcCloud.netlayer:tor.external:cfba681398c191a1906d6d023a3be28a8fa9b1f4eee52e966daf7b1ae630414f',
'org.apache.httpcomponents:httpclient:db3d1b6c2d6a5e5ad47577ad61854e2f0e0936199b8e05eb541ed52349263135',
'net.sf.jopt-simple:jopt-simple:6f45c00908265947c39221035250024f2caec9a15c1c8cf553ebeecee289f342',
'org.fxmisc.easybind:easybind:666af296dda6de68751668a62661571b5238ac6f1c07c8a204fc6f902b222aaf',
'network.bisq.btcd-cli4j:btcd-cli4j-daemon:c007116da1b0145ddee64bb3a54fef60d58ce5c3dcf27773f39471117be8f132',
'network.bisq.btcd-cli4j:btcd-cli4j-core:b1d0525f3629bad358ad4a40ea3be998220110331d4b9d24e76d7894e563a595',
'com.fasterxml.jackson.core:jackson-databind:fcf3c2b0c332f5f54604f7e27fa7ee502378a2cc5df6a944bbfae391872c32ff',
'com.fasterxml.jackson.core:jackson-core:39a74610521d7fb9eb3f437bb8739bbf47f6435be12d17bf954c731a0c6352bb',
'com.fasterxml.jackson.core:jackson-annotations:2566b3a6662afa3c6af4f5b25006cb46be2efc68f1b5116291d6998a8cdf7ed3',
'com.google.protobuf:protobuf-java:b5e2d91812d183c9f053ffeebcbcda034d4de6679521940a19064714966c2cd4',
'com.google.code.gson:gson:2d43eb5ea9e133d2ee2405cc14f5ee08951b8361302fdd93494a3a997b508d32',
'com.googlecode.json-simple:json-simple:4e69696892b88b41c55d49ab2fdcc21eead92bf54acc588c0050596c3b75199c',
'org.springframework:spring-core:c451e8417adb2ffb2445636da5e44a2f59307c4100037a1fe387c3fba4f29b52',
'ch.qos.logback:logback-classic:e66efc674e94837344bc5b748ff510c37a44eeff86cbfdbf9e714ef2eb374013',
'network.bisq.libdohj:libdohj-core:b89d2a6ad6a5aff1fccf2d4e5f7cc8c31991746e61913bcec3e999c2b0d7c954',
'com.github.bisq-network.bitcoinj:bitcoinj-core:d148d9577cf96540f7f5367011f7626ff9c9f148f0bf903b541740d480652969',
'org.slf4j:slf4j-api:3a4cd4969015f3beb4b5b4d81dbafc01765fb60b8a439955ca64d8476fef553e',
'ch.qos.logback:logback-core:4cd46fa17d77057b39160058df2f21ebbc2aded51d0edcc25d2c1cecc042a005',
'com.google.code.findbugs:jsr305:766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7',
'com.google.guava:guava:36a666e3b71ae7f0f0dca23654b67e086e6c93d192f60ba5dfd5519db6c288c8',
'com.google.inject:guice:9b9df27a5b8c7864112b4137fd92b36c3f1395bfe57be42fedf2f520ead1a93e',
'com.github.JesusMcCloud.netlayer:tor:ac8465b7dda30ea920ec31a6bde42df7e88bee0282e805ce2797628938e3cf0b',
'org.jetbrains.kotlin:kotlin-stdlib-jdk8:193ab7813e4d249f2ea4fc1b968fea8c2126bcbeeb5d6127050ce1b93dbaa7c2',
'io.github.microutils:kotlin-logging:4992504fd3c6ecdf9ed10874b9508e758bb908af9e9d7af19a61e9afb6b7e27a',
'org.jetbrains.kotlin:kotlin-stdlib-jdk7:877b59bbe466b24a88275a71fd06cd97359d2085420f6f1ac1d766afa8116001',
'org.jetbrains.kotlin:kotlin-stdlib:4ff0fcb97f4983b4aaba12668c24ad21b08460915db1b021d8f1d8bee687f21c',
'org.jetbrains:annotations:ace2a10dc8e2d5fd34925ecac03e4988b2c0f851650c94b8cef49ba1bd111478',
'org.bouncycastle:bcpg-jdk15on:de3355b821fc81dd32e1f3f560d5b3eca1c678fd2400011d0bfc69fb91bcde85',
'commons-io:commons-io:cc6a41dc3eaacc9e440a6bd0d2890b20d36b4ee408fe2d67122f328bb6e01581',
'org.apache.commons:commons-lang3:734c8356420cc8e30c795d64fd1fcd5d44ea9d90342a2cc3262c5158fbc6d98b',
'org.bouncycastle:bcprov-jdk15on:963e1ee14f808ffb99897d848ddcdb28fa91ddda867eb18d303e82728f878349',
'com.google.zxing:javase:0ec23e2ec12664ddd6347c8920ad647bb3b9da290f897a88516014b56cc77eb9',
'com.nativelibs4java:bridj:101bcd9b6637e6bc16e56deb3daefba62b1f5e8e9e37e1b3e56e3b5860d659cf',
'com.cedricwalter:tor-binary-macos:94f95e127c3409f870ee5c9fc642540c3ba865338cfaf3bb66d1e7e18c7fcee0',
'com.cedricwalter:tor-binary-linux32:af92b0b1ed40e3ff6c0f7b575ce44f19dfd666dfc6709e26cfb0f0bddca752eb',
'com.cedricwalter:tor-binary-linux64:f1fd937ef964e62abb13f62ddd53cd012316ecd09fecf1205e2db9f3333659c1',
'com.cedricwalter:tor-binary-windows:af7d67bc8f74b5c50f68b1aa5aa3e833470964f71882ee06ca40a32cd3dbc940',
'com.github.ravn:jsocks:3c71600af027b2b6d4244e4ad14d98ff2352a379410daebefff5d8cd48d742a4',
'org.apache.httpcomponents:httpcore:d7f853dee87680b07293d30855b39b9eb56c1297bd16ff1cd6f19ddb8fa745fb',
'commons-codec:commons-codec:ad19d2601c3abf0b946b5c3a4113e226a8c1e3305e395b90013b78dd94a723ce',
'commons-logging:commons-logging:daddea1ea0be0f56978ab3006b8ac92834afeefbd9b7e4e6316fca57df0fa636',
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
'aopalliance:aopalliance:0addec670fedcd3f113c5c8091d783280d23f75e3acb841b61a9cdb079376a08',
'com.lambdaworks:scrypt:9a82d218099fb14c10c0e86e7eefeebd8c104de920acdc47b8b4b7a686fb73b4',
'com.google.zxing:core:11aae8fd974ab25faa8208be50468eb12349cd239e93e7c797377fa13e381729',
'com.cedricwalter:tor-binary-geoip:fbd7656a262607e5a73016e048d5270cbabcd4639a1795b4b4e762df8877429d',
'com.github.JesusMcCloud:jtorctl:ba71601cbe50474ccc39a17bc6f7880c1412d8d19b94d37aee69ea2917f72046',
'org.apache.commons:commons-compress:5f2df1e467825e4cac5996d44890c4201c000b43c0b23cffc0782d28a0beb9b0',
'org.tukaani:xz:a594643d73cc01928cf6ca5ce100e094ea9d73af760a5d4fb6b75fa673ecec96',
'com.madgag.spongycastle:core:8d6240b974b0aca4d3da9c7dd44d42339d8a374358aca5fc98e50a995764511f',
'net.jcip:jcip-annotations:be5805392060c71474bf6c9a67a099471274d30b83eef84bfc4e0889a4f1dcc0',
'org.bitcoinj:orchid:f836325cfa0466a011cb755c9b0fee6368487a2352eb45f4306ad9e4c18de080',
'com.squareup.okhttp:okhttp:b4c943138fcef2bcc9d2006b2250c4aabbedeafc5947ed7c0af7fd103ceb2707',
'org.jetbrains.kotlin:kotlin-stdlib-common:4b161ef619eee0d1a49b1c4f0c4a8e46f4e342573efd8e0106a765f47475fe39',
'com.squareup.okio:okio:114bdc1f47338a68bcbc95abf2f5cdc72beeec91812f2fcd7b521c1937876266',
]
}
freimair marked this conversation as resolved.
Show resolved Hide resolved
58 changes: 58 additions & 0 deletions monitor/src/main/java/bisq/monitor/Configurable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.Properties;

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


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

/**
* Configure the Configurable.
*
* @param properties
*/
public void configure(final Properties properties) {
// only configure the Properties which belong to us
final Properties myProperties = new Properties();
properties.forEach((k, v) -> {
String key = (String) k;
if (key.startsWith(getName()))
myProperties.put(key.substring(key.indexOf(".") + 1), v);
});

// configure all properties that belong to us
this.configuration = myProperties;
}

protected String getName() {
return name;
}

protected void setName(String name) {
this.name = name;
}
}
155 changes: 155 additions & 0 deletions monitor/src/main/java/bisq/monitor/Metric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* 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.Properties;

import lombok.extern.slf4j.Slf4j;

/**
* Metric base class.
*
* @author Florian Reimair
*/
@Slf4j
public abstract class Metric extends Configurable implements Runnable {

private static final String INTERVAL = "run.interval";
private volatile boolean shutdown = false;

/**
* our reporter
*/
protected final Reporter reporter;
private Thread thread = new Thread();

/**
* disable execution
*/
private void disable() {
shutdown = true;
}

/**
* enable execution
*/
private void enable() {
shutdown = false;

thread = new Thread(this);

// set human readable name
thread.setName(getName());

// set as daemon, so that the jvm does not terminate the thread
thread.setDaemon(true);

thread.start();
}

/**
* Constructor.
*/
protected Metric(Reporter reporter) {

this.reporter = reporter;

setName(this.getClass().getSimpleName());

// disable by default
disable();
}

protected boolean enabled() {
return !shutdown;
}

/**
* Configures the Metric.
*
* @param properties
*/
public void configure(final Properties properties) {
synchronized (this) {
log.info("{} (re)loading config...", getName());
super.configure(properties);
reporter.configure(properties);

// decide whether to enable or disable the task
if (configuration.isEmpty() || !configuration.getProperty("enabled", "false").equals("true")
|| !configuration.containsKey(INTERVAL)) {
disable();

// some informative log output
if (configuration.isEmpty())
log.error("{} is not configured at all. Will not run.", getName());
else if (!configuration.getProperty("enabled", "false").equals("true"))
log.info("{} is deactivated. Will not run.", getName());
else if (!configuration.containsKey(INTERVAL))
log.error("{} is missing mandatory '" + INTERVAL + "' property. Will not run.", getName());
else
log.error("{} is misconfigured. Will not run.", getName());
} else if (!enabled() && configuration.getProperty("enabled", "false").equals("true")) {
// check if this Metric got activated after being disabled.
// if so, resume execution
enable();
log.info("{} got activated. Starting up.", getName());
}
}
}

public void run() {
while (!shutdown) {
// if not, execute all the things
synchronized (this) {
execute();
}

// make sure our configuration is not changed in the moment we want to query it
String interval;
synchronized (this) {
interval = configuration.getProperty(INTERVAL);
}

// and go to sleep for the configured amount of time.
try {
Thread.sleep(Long.parseLong(interval) * 1000);
} catch (InterruptedException ignore) {
}
}
log.info("{} shutdown", getName());
}

/**
* Gets scheduled repeatedly.
*/
protected abstract void execute();

/**
* Initiate graceful shutdown of the Metric.
*/
public void shutdown() {
log.debug("{} shutdown requested", getName());
shutdown = true;
}

protected void join() throws InterruptedException {
thread.join();
}

}
Loading