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

Report HS version to pricenode #4027

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,8 +48,13 @@ public PriceProvider(HttpClient httpClient, String baseUrl) {

public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOException {
Map<String, MarketPrice> 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<String, Long> tsMap = new HashMap<>();
Expand Down
8 changes: 7 additions & 1 deletion p2p/src/main/java/bisq/network/p2p/P2PService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
});
}
}
Expand Down
41 changes: 41 additions & 0 deletions pricenode/install_hsversion_debian.sh
Original file line number Diff line number Diff line change
@@ -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!'
20 changes: 20 additions & 0 deletions pricenode/journalscraper_hsversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL=750

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
29 changes: 29 additions & 0 deletions pricenode/uninstall_hsversion_debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
set -e

echo "[*] Network Size Monitoring removal script"

##### change paths if necessary for your system

ROOT_USER=root

SCRAPER_HOME=/journalreader

#####
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 '/<Plugin exec>.*/ {N;N; s/<Plugin exec>.*scraperscript_hsversion.sh.*<.Plugin>//g}' /etc/collectd/collectd.conf

echo "[*] Restarting services"
sudo -H -i -u "${ROOT_USER}" systemctl restart collectd.service

echo '[*] Done!'