add geoip node mapping and cleanup dockerfiles

v0.18.3.1
lza_menace 1 year ago
parent 4650866877
commit 086b023dfc

@ -21,7 +21,6 @@ chown -R debian-tor:debian-tor /run/tor
chmod 700 -R /run/tor chmod 700 -R /run/tor
mkdir -p /var/www/tor mkdir -p /var/www/tor
cat << EOF > /etc/tor/torrc cat << EOF > /etc/tor/torrc
BridgeRelay 1
ControlSocket /run/tor/control ControlSocket /run/tor/control
ControlSocketsGroupWritable 1 ControlSocketsGroupWritable 1
CookieAuthentication 1 CookieAuthentication 1

@ -32,7 +32,7 @@ services:
- -config=/etc/grafana/grafana.ini - -config=/etc/grafana/grafana.ini
container_name: monerod_grafana container_name: monerod_grafana
restart: unless-stopped restart: unless-stopped
image: grafana/grafana:${GRAFANA_TAG:-8.5.4} image: grafana/grafana:${GRAFANA_TAG:-10.1.4}
ports: ports:
- 127.0.0.1:${GRAF_PORT:-3000}:3000 - 127.0.0.1:${GRAF_PORT:-3000}:3000
volumes: volumes:
@ -58,13 +58,25 @@ services:
container_name: monerod_exporter container_name: monerod_exporter
build: build:
context: dockerfiles context: dockerfiles
dockerfile: monerod_exporter dockerfile: exporter
restart: unless-stopped restart: unless-stopped
# ports: # ports:
# - 127.0.0.1:9000:9000 # - 127.0.0.1:9000:9000
command: command:
- --monero-addr=http://monerod:${UNRESTRICTED_PORT:-18083} - --monero-addr=http://monerod:${UNRESTRICTED_PORT:-18083}
<<: *log-config <<: *log-config
nodemapper:
container_name: monerod_nodemapper
restart: unless-stopped
build:
context: dockerfiles
dockerfile: nodemapper
environment:
NODE_HOST: monerod
NODE_PORT: 18083
# ports:
# - 127.0.0.1:${MAPPER_PORT:-5000}:5000
<<: *log-config
monerod: monerod:
container_name: monerod container_name: monerod
build: build:

@ -1,4 +1,4 @@
FROM ubuntu:22.04 FROM ubuntu:22.04 as OG
ENV MONERO_HASH 186800de18f67cca8475ce392168aabeb5709a8f8058b0f7919d7c693786d56b ENV MONERO_HASH 186800de18f67cca8475ce392168aabeb5709a8f8058b0f7919d7c693786d56b
ENV MONERO_DL_URL https://downloads.getmonero.org/cli/monero-linux-x64-v0.18.2.2.tar.bz2 ENV MONERO_DL_URL https://downloads.getmonero.org/cli/monero-linux-x64-v0.18.2.2.tar.bz2
@ -34,7 +34,9 @@ RUN wget -qO ${MONERO_DL_FILE} ${MONERO_DL_URL} \
WORKDIR /data WORKDIR /data
RUN wget https://gui.xmr.pm/files/block.txt -q # Copy to fresh Ubuntu image to reduce size
FROM ubuntu:22.04
COPY --from=OG /usr/local/bin/monerod /usr/local/bin/monerod
EXPOSE 18080 EXPOSE 18080
EXPOSE 18081 EXPOSE 18081

@ -0,0 +1,13 @@
FROM ubuntu:22.04 as OG
WORKDIR /srv/nodemapper
RUN apt update && apt install wget python3 python3-venv -y
RUN python3 -m venv .venv
RUN .venv/bin/pip install flask==3.0.0
RUN .venv/bin/pip install geoip2==4.7.0
RUN wget https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb -qO ./geoip.mmdb
COPY nodemapper.py app.py
ENTRYPOINT [ ".venv/bin/flask", "--app", "app", "run", "--host", "0.0.0.0" ]

@ -0,0 +1,56 @@
#!/usr/bin/env python3
"""
This is a lightweight web service which will retrieve a peer list
from a Monero node, determine GeoIP information, and return
a list of metrics in a Prometheus compatible structure.
Use it to start plotting maps of active node connections.
"""
import socket, struct
from os import environ as env
import requests
import geoip2.database
from flask import Flask, make_response
app = Flask(__name__)
NODE_HOST = env.get('NODE_HOST', 'monerod')
NODE_PORT = env.get('NODE_PORT', 18083)
def get_geoip(ip):
"""Takes an IP address and determines GeoIP data"""
with geoip2.database.Reader("./geoip.mmdb") as reader:
return reader.city(ip)
@app.route("/metrics")
def nodes():
"""Return all nodes"""
peers = list()
peer_list = requests.get(f'http://{NODE_HOST}:{NODE_PORT}/get_peer_list').json()
def add_peer(host, status):
geo = get_geoip(host)
geostr = 'geoip{{latitude="{lat}", longitude="{lon}", country_code="{country_code}", country_name="{country_name}", status="{status}"}} 1'
if geostr not in peers:
peers.append(geostr.format(
lat=geo.location.latitude,
lon=geo.location.longitude,
country_code=geo.continent.code,
country_name=geo.continent.names['en'],
status=status
))
for peer in peer_list['gray_list']:
if peer.get('host'):
add_peer(peer['host'], 'gray')
for peer in peer_list['white_list']:
if peer.get('host'):
add_peer(peer['host'], 'white')
data = '\n'.join(peers)
response = make_response(data, 200)
response.mimetype = "text/plain"
return response

File diff suppressed because it is too large Load Diff

@ -1,9 +1,11 @@
global: global:
scrape_interval: 10s evaluation_interval: 10m
evaluation_interval: 10s
external_labels:
monitor: node-exporter
scrape_configs: scrape_configs:
- job_name: "node-exporter" - job_name: "node-exporter"
scrape_interval: 20s
static_configs: static_configs:
- targets: ["exporter:9000"] - targets: ["exporter:9000"]
- job_name: "nodemapper"
scrape_interval: 2m
static_configs:
- targets: ["nodemapper:5000"]

Loading…
Cancel
Save