diff --git a/.images.lock.yaml b/.images.lock.yaml new file mode 100644 index 0000000..94ceccb --- /dev/null +++ b/.images.lock.yaml @@ -0,0 +1,16 @@ +apiVersion: kbld.k14s.io/v1alpha1 +kind: Config +minimumRequiredVersion: 0.30.0 +overrides: +- image: monero-exporter + newImage: index.docker.io/utxobr/monero-exporter@sha256:da1a13e78a9aeacac10b576824d4195a14bc1e5ba9919770d2f81cb9d32c0d4d + preresolved: true +- image: monero-exporter-grafana + newImage: index.docker.io/utxobr/monero-exporter-grafana@sha256:f9c47963d3fb573166881baf1a9f2ad331500e34b4604d430f96957ab7bb1449 + preresolved: true +- image: monero-exporter-monerod + newImage: index.docker.io/utxobr/monero-exporter-monerod@sha256:2cea588aaf937025daddc1dabaa3e90d74fd07f3a2a1b84adc79d7f0f3fc9057 + preresolved: true +- image: monero-exporter-prometheus + newImage: index.docker.io/utxobr/monero-exporter-prometheus@sha256:f0a94da3052b0546a5a332401244d7cf63f80c74937511ac45f330c39503edac + preresolved: true diff --git a/.images.lock.yaml.asc b/.images.lock.yaml.asc new file mode 100644 index 0000000..d5cef18 --- /dev/null +++ b/.images.lock.yaml.asc @@ -0,0 +1,33 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +apiVersion: kbld.k14s.io/v1alpha1 +kind: Config +minimumRequiredVersion: 0.30.0 +overrides: +- - image: monero-exporter + newImage: index.docker.io/utxobr/monero-exporter@sha256:da1a13e78a9aeacac10b576824d4195a14bc1e5ba9919770d2f81cb9d32c0d4d + preresolved: true +- - image: monero-exporter-grafana + newImage: index.docker.io/utxobr/monero-exporter-grafana@sha256:f9c47963d3fb573166881baf1a9f2ad331500e34b4604d430f96957ab7bb1449 + preresolved: true +- - image: monero-exporter-monerod + newImage: index.docker.io/utxobr/monero-exporter-monerod@sha256:2cea588aaf937025daddc1dabaa3e90d74fd07f3a2a1b84adc79d7f0f3fc9057 + preresolved: true +- - image: monero-exporter-prometheus + newImage: index.docker.io/utxobr/monero-exporter-prometheus@sha256:f0a94da3052b0546a5a332401244d7cf63f80c74937511ac45f330c39503edac + preresolved: true +-----BEGIN PGP SIGNATURE----- + +iQGzBAEBCgAdFiEEnNETE4V4WcwPrek7a5MXemLQHbgFAmEJal0ACgkQa5MXemLQ +HbjoHQv+M+gO/5i+n/OYaFod2bikReB0bF2+yBcZ/mEw2diQBWCvX+Hd/IMMso39 +GqBh5eC42rEaRCJA9UniFJDWSNKHhuVoGwgEueiXL463HYDA+PNdR3pwf53h6Gq1 +e1jp4dldF2iwyBo3s0J4pb+KXi7lMtE+OZkKlWWUHrpaQEob/zrz6Ww/gGvCbVY7 +VXDzwi2ZbYjqdKxMvseGGJztcuCci+KE7OW3FCeTTuZxeYwoch5cA5dBll43z9zE +jtljsVRzkTxPaKKqc0jxdAmyY5GecYvIFn6sjqLRb2cVtKq18H8LhLcUnKoC1JRo +EbRb39Yc4DRstFRcDTKtKYaPvB3kamUj4sbtI5RBbj1wCnXX7l+8iEs3xvrIS7Op +1ItMlCM6ySKWRliDAu1OAsSHSJajGP9HEoqbNeY9yDMaHyrzO3jP9YHOX3a3EO4c +SHO/ESY4Pfrrnz7JMKaZKoZ3swxCrSJDTVS0jmv9uCk4rECKXO0asViWjAWNnvdw +DjQim7xU +=2yMM +-----END PGP SIGNATURE----- diff --git a/.images.yaml b/.images.yaml new file mode 100644 index 0000000..3d80303 --- /dev/null +++ b/.images.yaml @@ -0,0 +1,28 @@ +--- +apiVersion: kbld.k14s.io/v1alpha1 +kind: Config +sources: + - image: monero-exporter + path: ./ + - image: monero-exporter-monerod + path: ./examples/monerod + - image: monero-exporter-prometheus + path: ./examples/prometheus + - image: monero-exporter-grafana + path: ./examples/grafana +destinations: + - image: monero-exporter + newImage: docker.io/utxobr/monero-exporter + - image: monero-exporter-monerod + newImage: docker.io/utxobr/monero-exporter-monerod + - image: monero-exporter-prometheus + newImage: docker.io/utxobr/monero-exporter-prometheus + - image: monero-exporter-grafana + newImage: docker.io/utxobr/monero-exporter-grafana + +--- +images: + - image: monero-exporter + - image: monero-exporter-monerod + - image: monero-exporter-prometheus + - image: monero-exporter-grafana diff --git a/Dockerfile b/Dockerfile index 587d1c3..c2bdb3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,9 +14,8 @@ FROM $BUILDER_IMAGE as builder RUN set -x && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on \ go build -a -v \ - -ldflags "-s -w -X main.version=$(git tag) -X main.commit=$(git rev-parse HEAD)" \ - -tags osusergo,netgo,static_build \ -trimpath \ + -tags osusergo,netgo,static_build \ -o monero-exporter \ ./cmd/monero-exporter @@ -24,7 +23,7 @@ FROM $BUILDER_IMAGE as builder FROM $RUNTIME_IMAGE WORKDIR / - COPY --from=builder /workspace/monero-exporter . - USER 65532:65532 + COPY --chown=nonroot:nonroot --from=builder /workspace/monero-exporter . + USER nonroot:nonroot ENTRYPOINT ["/monero-exporter"] diff --git a/Makefile b/Makefile index f105cde..459743c 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ +SPACE := $(subst ,, ) + + install: go install -v ./cmd/monero-exporter run: monero-exporter \ --monero-addr=http://localhost:18081 \ - --bind-addr=:9000 \ - --geoip-filepath=./hack/geoip.mmdb + --bind-addr=:9000 test: go test ./... @@ -17,3 +19,11 @@ lint: table-of-contents: doctoc --notitle ./README.md + + +.images.lock.yaml: .images.yaml + kbld -f $< --lock-output $@ +.PHONY: .images.lock.yaml + +examples/docker-compose.yaml: .images.lock.yaml ./examples/docker-compose.base.yaml + kbld --images-annotation=false $(subst $(SPACE), -f , $^) > $@ diff --git a/README.md b/README.md index f3ebc00..87b06e9 100644 --- a/README.md +++ b/README.md @@ -131,13 +131,45 @@ See [INSTALL.md] for details and examples. This repository includes a sample dashboard that makes use of the metrics exposed via this exporter (see [./grafana](./grafana)). -Some screenshots from it: +Some screenshots of it: ![](./.github/assets/grafana-transaction-pool.png) ![](./.github/assets/grafana-last-block.png) ![](./.github/assets/grafana-networking.png) ![](./.github/assets/grafana-rpc.png) +_ps.: DO NOT publicly run the example Grafana setup without tweaking the +configuration - it is way more permissive than you'd want a Grafana instance +to be._ + + +## Example + +Under [./examples](./examples) you'll find a setup that makes use of +[docker-compose] to bring up Prometheus, Grafana, and monero-exporter +targetting an already running monero daemon (see +[docker-compose.yaml](./examples/docker-compose.yaml)). + +To run it, make sure you have `docker` and `docker-compose` installed. That +done, run: + +```bash +# get inside the examples directory +# +cd ./examples + + +# brings the services (monerod, monero-exporter, grafana, and prometheus) up +# in the background +# +docker-compose up -d + + +# follow the logs from those services +# +docker-compose logs -f +``` + ## Metrics @@ -299,3 +331,4 @@ See [LICENSE](./LICENSE). [prometheus]: https://prometheus.io [promql]: https://prometheus.io/docs/prometheus/latest/querying/basics/ [releases page]: https://github.com/cirocosta/monero-exporter/releases +[docker-compose]: https://docs.docker.com/compose/ diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 61a9c1b..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,44 +0,0 @@ -version: '3' - -services: - prometheus: - image: prom/prometheus - container_name: prometheus - network_mode: host - volumes: - - prometheus:/prometheus - entrypoint: - - /bin/sh - - -c - - | - echo " - global: - scrape_interval: '15s' - evaluation_interval: '15s' - - scrape_configs: - - job_name: 'monerod' - static_configs: - - targets: - - '127.0.0.1:9000' - " > config.yml - - exec prometheus \ - --config.file=config.yml \ - --storage.tsdb.retention.time=30d \ - --storage.tsdb.path=/prometheus - - - grafana: - container_name: grafana - build: ./grafana - ports: - - 3000:3000 - environment: - - GF_INSTALL_PLUGINS=grafana-worldmap-panel - volumes: - - ./grafana/dashboards:/var/lib/grafana/dashboards:ro - - -volumes: - prometheus: diff --git a/examples/docker-compose.base.yaml b/examples/docker-compose.base.yaml new file mode 100644 index 0000000..33d2e31 --- /dev/null +++ b/examples/docker-compose.base.yaml @@ -0,0 +1,72 @@ +# base `docker-compose` file with no explicit references to images. +# +# this is solely used as a template for `kbld`[1] which reads it and replaces +# image names by absolute digest-based image references. +# +# - see `monero-exporter/.images.lock.yaml` for the locked set of images used. +# - see `monero-exporter/.images.yaml` for the configuration for building the +# images. +# +# [1]: https://carvel.dev/kbld +# + +version: '3' + +services: + monerod: + container_name: monerod + image: monero-exporter-monerod + volumes: + - monerod-data:/data + ports: + - 18080:18080 + - 18089:18089 + command: + - --check-updates=disabled + - --data-dir=/data + - --enforce-dns-checkpointing + - --limit-rate=999999 + - --no-igd + - --no-zmq + - --out-peers=32 + - --p2p-bind-ip=127.0.0.1 + - --p2p-bind-port=18080 + - --rpc-bind-ip=127.0.0.1 + - --rpc-bind-port=18081 + - --rpc-restricted-bind-ip=0.0.0.0 + - --rpc-restricted-bind-port=18089 + + monero-exporter: + container_name: monero-exporter + image: monero-exporter + network_mode: service:monerod + command: + - --monero-addr=http://127.0.0.1:18081 + + prometheus: + image: monero-exporter-prometheus + container_name: prometheus + volumes: + - prometheus-data:/data + - ./prometheus/config.yaml:/etc/prometheus/config.yaml:ro + command: + - --config.file=/etc/prometheus/config.yaml + - --storage.tsdb.path=/data + - --storage.tsdb.retention.time=30d + + grafana: + container_name: grafana + image: monero-exporter-grafana + command: + - -config=/etc/grafana/grafana.ini + volumes: + - ./grafana/grafana.ini:/etc/grafana/grafana.ini:ro + - ./grafana/provisioning:/etc/grafana/provisioning:ro + - ./grafana/dashboards:/var/lib/grafana/dashboards:ro + ports: + - 3000:3000 + + +volumes: + prometheus-data: + monerod-data: diff --git a/examples/docker-compose.yaml b/examples/docker-compose.yaml new file mode 100644 index 0000000..ac52180 --- /dev/null +++ b/examples/docker-compose.yaml @@ -0,0 +1,55 @@ +--- +services: + grafana: + command: + - -config=/etc/grafana/grafana.ini + container_name: grafana + image: index.docker.io/utxobr/monero-exporter-grafana@sha256:f9c47963d3fb573166881baf1a9f2ad331500e34b4604d430f96957ab7bb1449 + ports: + - 3000:3000 + volumes: + - ./grafana/grafana.ini:/etc/grafana/grafana.ini:ro + - ./grafana/provisioning:/etc/grafana/provisioning:ro + - ./grafana/dashboards:/var/lib/grafana/dashboards:ro + monero-exporter: + command: + - --monero-addr=http://127.0.0.1:18081 + container_name: monero-exporter + image: index.docker.io/utxobr/monero-exporter@sha256:da1a13e78a9aeacac10b576824d4195a14bc1e5ba9919770d2f81cb9d32c0d4d + network_mode: service:monerod + monerod: + command: + - --check-updates=disabled + - --data-dir=/data + - --enforce-dns-checkpointing + - --limit-rate=999999 + - --no-igd + - --no-zmq + - --out-peers=32 + - --p2p-bind-ip=127.0.0.1 + - --p2p-bind-port=18080 + - --rpc-bind-ip=127.0.0.1 + - --rpc-bind-port=18081 + - --rpc-restricted-bind-ip=0.0.0.0 + - --rpc-restricted-bind-port=18089 + container_name: monerod + image: index.docker.io/utxobr/monero-exporter-monerod@sha256:2cea588aaf937025daddc1dabaa3e90d74fd07f3a2a1b84adc79d7f0f3fc9057 + ports: + - 18080:18080 + - 18089:18089 + volumes: + - monerod-data:/data + prometheus: + command: + - --config.file=/etc/prometheus/config.yaml + - --storage.tsdb.path=/data + - --storage.tsdb.retention.time=30d + container_name: prometheus + image: index.docker.io/utxobr/monero-exporter-prometheus@sha256:f0a94da3052b0546a5a332401244d7cf63f80c74937511ac45f330c39503edac + volumes: + - prometheus-data:/data + - ./prometheus/config.yaml:/etc/prometheus/config.yaml:ro +version: "3" +volumes: + monerod-data: null + prometheus-data: null diff --git a/examples/grafana/Dockerfile b/examples/grafana/Dockerfile new file mode 100644 index 0000000..11d221f --- /dev/null +++ b/examples/grafana/Dockerfile @@ -0,0 +1,30 @@ +ARG BUILDER_IMAGE=index.docker.io/library/ubuntu@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93 +ARG RUNTIME_IMAGE=gcr.io/distroless/base@sha256:bc84925113289d139a9ef2f309f0dd7ac46ea7b786f172ba9084ffdb4cbd9490 + + +FROM $BUILDER_IMAGE AS builder + + ARG VERSION=8.0.6 + ARG SHA256=252a4d022f4dbd9a68d07cdd0e6762d62fa53462f294781cb53e8f3d61cd8649 + + RUN set -ex && \ + apt update && \ + apt install -y curl gzip + + RUN set -ex && \ + curl -SOL https://dl.grafana.com/oss/release/grafana-${VERSION}.linux-amd64.tar.gz && \ + echo "${SHA256} grafana-${VERSION}.linux-amd64.tar.gz" | sha256sum -c && \ + tar xzf grafana-${VERSION}.linux-amd64.tar.gz --strip-components=1 + + +FROM $RUNTIME_IMAGE + + USER nonroot:nonroot + WORKDIR /grafana + + COPY --from=builder --chown=nonroot:nonroot /bin/grafana-server /usr/local/bin/grafana-server + COPY --from=builder --chown=nonroot:nonroot /public /grafana/public + COPY --from=builder --chown=nonroot:nonroot /conf /grafana/conf + + + ENTRYPOINT [ "grafana-server" ] diff --git a/grafana/dashboards/monero.json b/examples/grafana/dashboards/monero.json similarity index 100% rename from grafana/dashboards/monero.json rename to examples/grafana/dashboards/monero.json diff --git a/grafana/config.ini b/examples/grafana/grafana.ini similarity index 100% rename from grafana/config.ini rename to examples/grafana/grafana.ini diff --git a/grafana/provisioning/dashboards/all.yaml b/examples/grafana/provisioning/dashboards/all.yaml similarity index 100% rename from grafana/provisioning/dashboards/all.yaml rename to examples/grafana/provisioning/dashboards/all.yaml diff --git a/grafana/provisioning/datasources/all.yaml b/examples/grafana/provisioning/datasources/all.yaml similarity index 82% rename from grafana/provisioning/datasources/all.yaml rename to examples/grafana/provisioning/datasources/all.yaml index 82aef7f..10d9ced 100644 --- a/grafana/provisioning/datasources/all.yaml +++ b/examples/grafana/provisioning/datasources/all.yaml @@ -5,7 +5,7 @@ datasources: type: prometheus access: proxy orgId: 1 - url: http://xps.utxo.com.br:9090 + url: http://prometheus:9090 isDefault: true version: 1 editable: false diff --git a/examples/monerod/Dockerfile b/examples/monerod/Dockerfile new file mode 100644 index 0000000..c066ab7 --- /dev/null +++ b/examples/monerod/Dockerfile @@ -0,0 +1,29 @@ +ARG BUILDER_IMAGE=index.docker.io/library/ubuntu@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93 +ARG RUNTIME_IMAGE=gcr.io/distroless/base@sha256:bc84925113289d139a9ef2f309f0dd7ac46ea7b786f172ba9084ffdb4cbd9490 + + +FROM $BUILDER_IMAGE AS builder + + ARG MONERO_VERSION=0.17.2.0 + ARG MONERO_SHA256=59e16c53b2aff8d9ab7a8ba3279ee826ac1f2480fbb98e79a149e6be23dd9086 + + RUN set -ex && \ + apt update && \ + apt install -y curl bzip2 + + RUN set -ex && \ + curl -SOL https://downloads.getmonero.org/cli/monero-linux-x64-v${MONERO_VERSION}.tar.bz2 && \ + echo "${MONERO_SHA256} monero-linux-x64-v${MONERO_VERSION}.tar.bz2" | sha256sum -c && \ + tar xf monero-linux-x64-v${MONERO_VERSION}.tar.bz2 --strip-components=1 && \ + mv ./monerod /usr/local/bin/monerod + + RUN mkdir /data + + +FROM $RUNTIME_IMAGE + + COPY --from=builder --chown=nonroot:nonroot /data /data + COPY --from=builder --chown=nonroot:nonroot /usr/local/bin/monerod /usr/local/bin/monerod + USER nonroot:nonroot + + ENTRYPOINT [ "monerod", "--non-interactive" ] diff --git a/examples/prometheus/Dockerfile b/examples/prometheus/Dockerfile new file mode 100644 index 0000000..13324c9 --- /dev/null +++ b/examples/prometheus/Dockerfile @@ -0,0 +1,29 @@ +ARG BUILDER_IMAGE=index.docker.io/library/ubuntu@sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93 +ARG RUNTIME_IMAGE=gcr.io/distroless/base@sha256:bc84925113289d139a9ef2f309f0dd7ac46ea7b786f172ba9084ffdb4cbd9490 + + +FROM $BUILDER_IMAGE AS builder + + ARG VERSION=2.28.1 + ARG SHA256=91dd91e13f30fe520e01175ca1027dd09a458d4421a584ba557ba88b38803f27 + + RUN set -ex && \ + apt update && \ + apt install -y curl gzip + + RUN set -ex && \ + curl -SOL https://github.com/prometheus/prometheus/releases/download/v${VERSION}/prometheus-${VERSION}.linux-amd64.tar.gz && \ + echo "${SHA256} prometheus-${VERSION}.linux-amd64.tar.gz" | sha256sum -c && \ + tar xvzf prometheus-${VERSION}.linux-amd64.tar.gz --strip-components=1 && \ + mv ./prometheus /usr/local/bin/prometheus + + RUN mkdir /data + + +FROM $RUNTIME_IMAGE + + COPY --from=builder --chown=nonroot:nonroot /data /data + COPY --from=builder --chown=nonroot:nonroot /usr/local/bin/prometheus /usr/local/bin/prometheus + USER nonroot:nonroot + + ENTRYPOINT [ "prometheus" ] diff --git a/examples/prometheus/config.yaml b/examples/prometheus/config.yaml new file mode 100644 index 0000000..b387614 --- /dev/null +++ b/examples/prometheus/config.yaml @@ -0,0 +1,8 @@ +global: + scrape_interval: '15s' + evaluation_interval: '15s' +scrape_configs: + - job_name: 'monerod' + static_configs: + - targets: + - 'monerod:9000' diff --git a/grafana/Dockerfile b/grafana/Dockerfile deleted file mode 100644 index a470545..0000000 --- a/grafana/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM grafana/grafana - -ADD ./config.ini /etc/grafana/grafana.ini -ADD ./provisioning /etc/grafana/provisioning