From 7bc9095c0ab8afa239c66da50e03c595e3761883 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 17 Nov 2025 14:47:04 +0100 Subject: [PATCH 1/3] Migrate to Grafana Alloy as the recommended replacement for log forwarding. --- .env.sample.holesky | 10 ++--- .env.sample.hoodi | 10 ++--- .env.sample.mainnet | 10 ++--- alloy/config.alloy.example | 87 ++++++++++++++++++++++++++++++++++++++ alloy/run.sh | 34 +++++++++++++++ compose-monitoring.yml | 11 +++-- promtail/run.sh | 26 ------------ 7 files changed, 141 insertions(+), 47 deletions(-) create mode 100644 alloy/config.alloy.example create mode 100755 alloy/run.sh delete mode 100755 promtail/run.sh diff --git a/.env.sample.holesky b/.env.sample.holesky index 6f10269c..9ff029ab 100644 --- a/.env.sample.holesky +++ b/.env.sample.holesky @@ -176,14 +176,14 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 # Loki log aggregation server addresses. Disable loki log aggregation by setting an empty address. #CHARON_LOKI_ADDRESSES= -# Charon Cluster Name. Mandatory to send logs with Promtail and metrics with Prometheus. -#CLUSTER_NAME= +# Charon Cluster Name. Mandatory to send logs with Promtail. +#CLUSTER_NAME="" -# Charon Cluster Peer. Mandatory to send logs with Promtail and metrics with Prometheus. -#CLUSTER_PEER= +# Charon Cluster Peer. Mandatory to send logs with Promtail. +#CLUSTER_PEER="" # Nickname to identify this charon node on monitoring (max 32 characters). -#CHARON_NICKNAME= +#CHARON_NICKNAME="" # Docker network of running charon node. See `docker network ls`. #CHARON_DOCKER_NETWORK= diff --git a/.env.sample.hoodi b/.env.sample.hoodi index 034022ec..0655a583 100644 --- a/.env.sample.hoodi +++ b/.env.sample.hoodi @@ -176,14 +176,14 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 # Loki log aggregation server addresses. Disable loki log aggregation by setting an empty address. #CHARON_LOKI_ADDRESSES= -# Charon Cluster Name. Mandatory to send logs with Promtail and metrics with Prometheus. -#CLUSTER_NAME= +# Charon Cluster Name. Mandatory to send logs with Promtail. +#CLUSTER_NAME="" -# Charon Cluster Peer. Mandatory to send logs with Promtail and metrics with Prometheus. -#CLUSTER_PEER= +# Charon Cluster Peer. Mandatory to send logs with Promtail. +#CLUSTER_PEER="" # Nickname to identify this charon node on monitoring (max 32 characters). -#CHARON_NICKNAME= +#CHARON_NICKNAME="" # Docker network of running charon node. See `docker network ls`. #CHARON_DOCKER_NETWORK= diff --git a/.env.sample.mainnet b/.env.sample.mainnet index 70768b69..260308fc 100644 --- a/.env.sample.mainnet +++ b/.env.sample.mainnet @@ -176,14 +176,14 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 # Loki log aggregation server addresses. Disable loki log aggregation by setting an empty address. #CHARON_LOKI_ADDRESSES= -# Charon Cluster Name. Mandatory to send logs with Promtail and metrics with Prometheus. -#CLUSTER_NAME= +# Charon Cluster Name. Mandatory to send logs with Promtail. +#CLUSTER_NAME="" -# Charon Cluster Peer. Mandatory to send logs with Promtail and metrics with Prometheus. -#CLUSTER_PEER= +# Charon Cluster Peer. Mandatory to send logs with Promtail. +#CLUSTER_PEER="" # Nickname to identify this charon node on monitoring (max 32 characters). -#CHARON_NICKNAME= +#CHARON_NICKNAME="" # Docker network of running charon node. See `docker network ls`. #CHARON_DOCKER_NETWORK= diff --git a/alloy/config.alloy.example b/alloy/config.alloy.example new file mode 100644 index 00000000..1329e9f5 --- /dev/null +++ b/alloy/config.alloy.example @@ -0,0 +1,87 @@ +discovery.docker "docker" { + host = "unix:///var/run/docker.sock" +} + +loki.process "docker" { + forward_to = [loki.write.default.receiver] + + stage.docker { } +} + +discovery.relabel "docker" { + targets = discovery.docker.docker.targets + + rule { + source_labels = ["__meta_docker_container_label_promtail_monitored"] + regex = "true" + action = "keep" + } + + rule { + source_labels = ["__meta_docker_container_name"] + regex = "/(.*)" + target_label = "container" + } + + rule { + source_labels = ["container"] + regex = ".*charon.*" + target_label = "job" + replacement = "charon" + } + + rule { + source_labels = ["container"] + regex = ".*nethermind.*" + target_label = "job" + replacement = "nethermind" + } + + rule { + source_labels = ["container"] + regex = ".*lodestar.*" + target_label = "job" + replacement = "lodestar" + } + + rule { + source_labels = ["container"] + regex = ".*lighthouse.*" + target_label = "job" + replacement = "lighthouse" + } + + rule { + source_labels = ["container"] + regex = ".*mev-boost.*" + target_label = "job" + replacement = "mev-boost" + } + + rule { + target_label = "cluster_name" + replacement = "$CLUSTER_NAME" + } + + rule { + target_label = "cluster_peer" + replacement = "$CLUSTER_PEER" + } +} + +loki.source.docker "docker" { + host = "unix:///var/run/docker.sock" + targets = discovery.docker.docker.targets + forward_to = [loki.process.docker.receiver] + relabel_rules = discovery.relabel.docker.rules +} + +loki.write "default" { + endpoint { + url = "$CHARON_LOKI_ADDRESSES" + } + external_labels = { + cluster_name = "$CLUSTER_NAME", + cluster_peer = "$CLUSTER_PEER", + } +} diff --git a/alloy/run.sh b/alloy/run.sh new file mode 100755 index 00000000..a1290119 --- /dev/null +++ b/alloy/run.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +if [ -z "${CHARON_LOKI_ADDRESSES:-}" ]; then + echo "Error: \$CHARON_LOKI_ADDRESSES variable is empty" >&2 + exit 1 +fi + +if [ -z "${CLUSTER_NAME:-}" ]; then + echo "Error: \$CLUSTER_NAME variable is empty" >&2 + exit 1 +fi + +if [ -z "${CLUSTER_PEER:-}" ]; then + echo "Error: \$CLUSTER_PEER variable is empty" >&2 + exit 1 +fi + +SRC="/etc/alloy/config.alloy.example" +DST="/etc/alloy/config.alloy" + +echo "Rendering template: $SRC -> $DST" + +sed -e "s|\$CHARON_LOKI_ADDRESSES|${CHARON_LOKI_ADDRESSES}|g" \ + -e "s|\$CLUSTER_NAME|${CLUSTER_NAME}|g" \ + -e "s|\$CLUSTER_PEER|${CLUSTER_PEER}|g" \ + "$SRC" > "$DST" + +echo "Config successfully rendered to $DST" + +# Execute the command passed as arguments if any +if [ $# -gt 0 ]; then + echo "Executing: $@" + exec "$@" +fi diff --git a/compose-monitoring.yml b/compose-monitoring.yml index ddf02012..fda52999 100644 --- a/compose-monitoring.yml +++ b/compose-monitoring.yml @@ -46,19 +46,18 @@ services: - ./data/loki:/opt/loki restart: unless-stopped - promtail: - profiles: [monitoring-log-collector] - image: grafana/promtail:${PROMTAIL_VERSION:-2.8.2} + alloy: + image: grafana/alloy:${ALLOY_VERSION:-v1.11.3} environment: CHARON_LOKI_ADDRESSES: ${CHARON_LOKI_ADDRESSES} CLUSTER_NAME: ${CLUSTER_NAME} CLUSTER_PEER: ${CLUSTER_PEER} - command: -config.file=/etc/promtail/config.yml volumes: - - ./promtail:/etc/promtail + - ./alloy:/etc/alloy - /var/run/docker.sock:/var/run/docker.sock networks: [dvnode] - entrypoint: /etc/promtail/run.sh + entrypoint: /etc/alloy/run.sh + command: ["/bin/alloy", "run", "/etc/alloy/config.alloy", "--storage.path=/var/lib/alloy/data"] restart: unless-stopped networks: diff --git a/promtail/run.sh b/promtail/run.sh deleted file mode 100755 index f8d33360..00000000 --- a/promtail/run.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -if [ -z "$CHARON_LOKI_ADDRESSES" ]; then - echo "Error: \$CHARON_LOKI_ADDRESSES variable is empty" >&2 - exit 1 -fi - -if [ -z "$CLUSTER_NAME" ]; then - echo "Error: \$CLUSTER_NAME variable is empty" >&2 - exit 1 -fi - -if [ -z "$CLUSTER_PEER" ]; then - echo "Error: \$CLUSTER_PEER variable is empty" >&2 - exit 1 -fi - -# Process the template file once -sed -e "s|\$CHARON_LOKI_ADDRESSES|${CHARON_LOKI_ADDRESSES}|g" \ - -e "s|\$CLUSTER_NAME|${CLUSTER_NAME}|g" \ - -e "s|\$CLUSTER_PEER|${CLUSTER_PEER}|g" \ - /etc/promtail/config.yml.example > /etc/promtail/config.yml - -# Start Promtail with the generated config -/usr/bin/promtail \ - -config.file=/etc/promtail/config.yml From c30d0c4c9dc8465394374f307e7f84dfa593323d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn=20Kyne?= Date: Thu, 11 Dec 2025 17:03:27 +0000 Subject: [PATCH 2/3] Fix rebase, re-add profile --- compose-monitoring.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/compose-monitoring.yml b/compose-monitoring.yml index fda52999..9750bb4f 100644 --- a/compose-monitoring.yml +++ b/compose-monitoring.yml @@ -47,6 +47,7 @@ services: restart: unless-stopped alloy: + profiles: [monitoring-log-collector] image: grafana/alloy:${ALLOY_VERSION:-v1.11.3} environment: CHARON_LOKI_ADDRESSES: ${CHARON_LOKI_ADDRESSES} From 70ede5ba65fd335d929de7df33f8a9c427200b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn=20Kyne?= Date: Wed, 7 Jan 2026 19:30:53 +0000 Subject: [PATCH 3/3] Reintroduce the empty string to prevent spaces making a mess --- .env.sample.holesky | 4 ++-- .env.sample.hoodi | 4 ++-- .env.sample.mainnet | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.env.sample.holesky b/.env.sample.holesky index 9ff029ab..f1f44162 100644 --- a/.env.sample.holesky +++ b/.env.sample.holesky @@ -176,10 +176,10 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 # Loki log aggregation server addresses. Disable loki log aggregation by setting an empty address. #CHARON_LOKI_ADDRESSES= -# Charon Cluster Name. Mandatory to send logs with Promtail. +# Charon Cluster Name. Mandatory to send logs with Promtail and metrics with Prometheus. #CLUSTER_NAME="" -# Charon Cluster Peer. Mandatory to send logs with Promtail. +# Charon Cluster Peer. Mandatory to send logs with Promtail and metrics with Prometheus. #CLUSTER_PEER="" # Nickname to identify this charon node on monitoring (max 32 characters). diff --git a/.env.sample.hoodi b/.env.sample.hoodi index 0655a583..deffff86 100644 --- a/.env.sample.hoodi +++ b/.env.sample.hoodi @@ -176,10 +176,10 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 # Loki log aggregation server addresses. Disable loki log aggregation by setting an empty address. #CHARON_LOKI_ADDRESSES= -# Charon Cluster Name. Mandatory to send logs with Promtail. +# Charon Cluster Name. Mandatory to send logs with Promtail and metrics with Prometheus. #CLUSTER_NAME="" -# Charon Cluster Peer. Mandatory to send logs with Promtail. +# Charon Cluster Peer. Mandatory to send logs with Promtail and metrics with Prometheus. #CLUSTER_PEER="" # Nickname to identify this charon node on monitoring (max 32 characters). diff --git a/.env.sample.mainnet b/.env.sample.mainnet index 260308fc..7c1b092b 100644 --- a/.env.sample.mainnet +++ b/.env.sample.mainnet @@ -176,10 +176,10 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 # Loki log aggregation server addresses. Disable loki log aggregation by setting an empty address. #CHARON_LOKI_ADDRESSES= -# Charon Cluster Name. Mandatory to send logs with Promtail. +# Charon Cluster Name. Mandatory to send logs with Promtail and metrics with Prometheus. #CLUSTER_NAME="" -# Charon Cluster Peer. Mandatory to send logs with Promtail. +# Charon Cluster Peer. Mandatory to send logs with Promtail and metrics with Prometheus. #CLUSTER_PEER="" # Nickname to identify this charon node on monitoring (max 32 characters).