From 5d382982ff9ec928c96443c38155ffa67d729b06 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Wed, 4 Mar 2020 14:04:30 +0100 Subject: [PATCH 1/5] Report HS version to pricenode In order to evaluate progress on https://github.com/bisq-network/projects/issues/23, the Bisq app reports its hiddenservice version. This change is going to be undone as soon as we do not need the info anymore. --- .../main/java/bisq/core/provider/price/PriceProvider.java | 8 +++++++- p2p/src/main/java/bisq/network/p2p/P2PService.java | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/provider/price/PriceProvider.java b/core/src/main/java/bisq/core/provider/price/PriceProvider.java index dcb68cc0240..d0ac27c2d72 100644 --- a/core/src/main/java/bisq/core/provider/price/PriceProvider.java +++ b/core/src/main/java/bisq/core/provider/price/PriceProvider.java @@ -20,6 +20,7 @@ import bisq.core.provider.HttpClientProvider; import bisq.network.http.HttpClient; +import bisq.network.p2p.P2PService; import bisq.common.app.Version; import bisq.common.util.MathUtils; @@ -47,8 +48,13 @@ public PriceProvider(HttpClient httpClient, String baseUrl) { public Tuple2, Map> getAll() throws IOException { Map marketPriceMap = new HashMap<>(); + String hsVersion = ""; + if (P2PService.getMyNodeAddress() != null) + hsVersion = P2PService.getMyNodeAddress().getHostName().length() > 22 ? ", HSv3" : ", HSv2"; + String json = httpClient.requestWithGET("getAllMarketPrices", "User-Agent", "bisq/" - + Version.VERSION); + + Version.VERSION + hsVersion); + LinkedTreeMap map = new Gson().fromJson(json, LinkedTreeMap.class); Map tsMap = new HashMap<>(); diff --git a/p2p/src/main/java/bisq/network/p2p/P2PService.java b/p2p/src/main/java/bisq/network/p2p/P2PService.java index 3a4db0c9df1..5caab46ec40 100644 --- a/p2p/src/main/java/bisq/network/p2p/P2PService.java +++ b/p2p/src/main/java/bisq/network/p2p/P2PService.java @@ -129,6 +129,9 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis private final KeepAliveManager keepAliveManager; private final Socks5ProxyProvider socks5ProxyProvider; + @Getter + private static NodeAddress myNodeAddress; + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -195,11 +198,14 @@ public void start(@Nullable P2PServiceListener listener) { public void onAllServicesInitialized() { if (networkNode.getNodeAddress() != null) { maybeProcessAllMailboxEntries(); + myNodeAddress = networkNode.getNodeAddress(); } else { // If our HS is still not published networkNode.nodeAddressProperty().addListener((observable, oldValue, newValue) -> { - if (newValue != null) + if (newValue != null) { maybeProcessAllMailboxEntries(); + myNodeAddress = networkNode.getNodeAddress(); + } }); } } From cc7f47464cfea1784ed35a492cb65d0932242abd Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Fri, 27 Mar 2020 11:48:09 +0100 Subject: [PATCH 2/5] Added hsversion scraper script --- pricenode/journalscraper_hsversion.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 pricenode/journalscraper_hsversion.sh diff --git a/pricenode/journalscraper_hsversion.sh b/pricenode/journalscraper_hsversion.sh new file mode 100755 index 00000000000..cc56553b270 --- /dev/null +++ b/pricenode/journalscraper_hsversion.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +HOSTNAME="${COLLECTD_HOSTNAME:-localhost}" +INTERVAL=5 + +last=$(date +"%F %T" -d "$INTERVAL seconds ago") +while true; +do + now=$(date +"%F %T") + + journalctl -u pricenode --since="$last" --until="$now" | grep -Eo "getAllMarketPrices.*HSv[0-9]" | grep -o "HSv[0-9]" | sort | uniq -c | while read -r line; do + number=$(echo "${line}" | cut -d ' ' -f 1); + version=$(echo "${line}" | cut -d \ -f 2); + version=${version//./_}; + echo "PUTVAL $HOSTNAME/hsversionStats/gauge-$version interval=$INTERVAL N:$number"; + done + last=$now + + sleep $INTERVAL +done From a7d32c8d0087b9c740ad3588a78cc7b2cdeb6a33 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Fri, 27 Mar 2020 12:24:06 +0100 Subject: [PATCH 3/5] Added installer/uninstaller --- pricenode/install_hsversion_debian.sh | 41 +++++++++++++++++++++++++ pricenode/uninstall_hsversion_debian.sh | 31 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 pricenode/install_hsversion_debian.sh create mode 100755 pricenode/uninstall_hsversion_debian.sh diff --git a/pricenode/install_hsversion_debian.sh b/pricenode/install_hsversion_debian.sh new file mode 100755 index 00000000000..631a02787cf --- /dev/null +++ b/pricenode/install_hsversion_debian.sh @@ -0,0 +1,41 @@ +#!/bin/sh +set -e + +echo "[*] Network Size Monitoring installation script" + +##### change paths if necessary for your system + +ROOT_USER=root + +SCRAPER_HOME=/journalreader +SCRAPER_USER=journalreader +SCRAPER_GROUP=systemd-journal + +##### +echo "[*] Checking environment..." +if [ ! -f "/etc/collectd/collectd.conf" ]; then + echo 'Collectd is not installed. Did you do the install_monitoring_debian.sh?' + echo 'Exiting...' + exit +fi +if ! grep -q "journalreader" /etc/passwd; then + echo 'User not found. Did you run the install_networksize_debian.sh?' + echo 'Exiting...' + exit +fi + +echo "[*] Installing journal parser script" +curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/journalscraper_hsversion.sh > /tmp/journalscraper_hsversion.sh +sudo -H -i -u "${ROOT_USER}" install -c -o "${SCRAPER_USER}" -g "${SCRAPER_GROUP}" -m 744 /tmp/journalscraper_hsversion.sh "${SCRAPER_HOME}/scraperscript_hsversion.sh" + +echo "[*] Installing collectd config" +curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/collectd.conf.snippet > /tmp/collectd.conf.snippet +sudo -H -i -u "${ROOT_USER}" sed -i -e "s/LoadPlugin exec//" /tmp/collectd.conf.snippet +sudo -H -i -u "${ROOT_USER}" /bin/sh -c "cat /tmp/collectd.conf.snippet >> /etc/collectd/collectd.conf" +sudo -H -i -u "${ROOT_USER}" sed -i -e "s/__USER_GROUP__/${SCRAPER_USER}:${SCRAPER_GROUP}/" /etc/collectd/collectd.conf +sudo -H -i -u "${ROOT_USER}" sed -i -e "s!__SCRAPERSCRIPT__!${SCRAPER_HOME}/scraperscript_hsversion.sh!" /etc/collectd/collectd.conf + +echo "[*] Restarting services" +sudo -H -i -u "${ROOT_USER}" systemctl restart collectd.service + +echo '[*] Done!' diff --git a/pricenode/uninstall_hsversion_debian.sh b/pricenode/uninstall_hsversion_debian.sh new file mode 100755 index 00000000000..fce6f364f50 --- /dev/null +++ b/pricenode/uninstall_hsversion_debian.sh @@ -0,0 +1,31 @@ +#!/bin/sh +set -e + +echo "[*] Network Size Monitoring removal script" + +##### change paths if necessary for your system + +ROOT_USER=root + +SCRAPER_HOME=/journalreader +SCRAPER_USER=journalreader +SCRAPER_GROUP=systemd-journal + +##### +echo "[*] Checking environment..." +if [ ! -f "${SCRAPER_HOME}/scraperscript_hsversion.sh" ]; then + echo 'There is nothing to be removed.' + echo 'Exiting...' + exit +fi + +echo "[*] Removing journal parser script" +sudo -H -i -u "${ROOT_USER}" rm "${SCRAPER_HOME}/scraperscript_hsversion.sh" + +echo "[*] Reverting collectd config" +sudo -H -i -u "${ROOT_USER}" sed -i '/.*/ {N;N; s/.*scraperscript_hsversion.sh.*<.Plugin>//g}' /etc/collectd/collectd.conf + +echo "[*] Restarting services" +sudo -H -i -u "${ROOT_USER}" systemctl restart collectd.service + +echo '[*] Done!' From 0b0aee74b8b01b9d90b7e0b67da20193eac707d2 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Mon, 30 Mar 2020 15:37:46 +0200 Subject: [PATCH 4/5] Cleanup --- pricenode/journalscraper_hsversion.sh | 2 +- pricenode/uninstall_hsversion_debian.sh | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pricenode/journalscraper_hsversion.sh b/pricenode/journalscraper_hsversion.sh index cc56553b270..9e7f8fc50e0 100755 --- a/pricenode/journalscraper_hsversion.sh +++ b/pricenode/journalscraper_hsversion.sh @@ -1,7 +1,7 @@ #!/bin/bash HOSTNAME="${COLLECTD_HOSTNAME:-localhost}" -INTERVAL=5 +INTERVAL=750 last=$(date +"%F %T" -d "$INTERVAL seconds ago") while true; diff --git a/pricenode/uninstall_hsversion_debian.sh b/pricenode/uninstall_hsversion_debian.sh index fce6f364f50..618e848953d 100755 --- a/pricenode/uninstall_hsversion_debian.sh +++ b/pricenode/uninstall_hsversion_debian.sh @@ -8,8 +8,6 @@ echo "[*] Network Size Monitoring removal script" ROOT_USER=root SCRAPER_HOME=/journalreader -SCRAPER_USER=journalreader -SCRAPER_GROUP=systemd-journal ##### echo "[*] Checking environment..." From 862ded2428d13fe9e3340ef8c8e2b8405d0e4549 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Wed, 1 Apr 2020 12:34:22 +0200 Subject: [PATCH 5/5] Fix unit name --- pricenode/journalscraper_hsversion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pricenode/journalscraper_hsversion.sh b/pricenode/journalscraper_hsversion.sh index 9e7f8fc50e0..f5d710b8b70 100755 --- a/pricenode/journalscraper_hsversion.sh +++ b/pricenode/journalscraper_hsversion.sh @@ -8,7 +8,7 @@ while true; do now=$(date +"%F %T") - journalctl -u pricenode --since="$last" --until="$now" | grep -Eo "getAllMarketPrices.*HSv[0-9]" | grep -o "HSv[0-9]" | sort | uniq -c | while read -r line; do + journalctl -u bisq-pricenode --since="$last" --until="$now" | grep -Eo "getAllMarketPrices.*HSv[0-9]" | grep -o "HSv[0-9]" | sort | uniq -c | while read -r line; do number=$(echo "${line}" | cut -d ' ' -f 1); version=$(echo "${line}" | cut -d \ -f 2); version=${version//./_};