diff --git a/.env.sample.holesky b/.env.sample.holesky index 84887bf5..c538e4fe 100644 --- a/.env.sample.holesky +++ b/.env.sample.holesky @@ -186,13 +186,13 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 #CHARON_LOKI_ADDRESSES= # Charon Cluster Name. Mandatory to send logs with Promtail. -#CLUSTER_NAME= +#CLUSTER_NAME="" # Charon Cluster Peer. Mandatory to send logs with Promtail. -#CLUSTER_PEER= +#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 3329a1f7..2a8cc7e1 100644 --- a/.env.sample.hoodi +++ b/.env.sample.hoodi @@ -187,13 +187,13 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 #CHARON_LOKI_ADDRESSES= # Charon Cluster Name. Mandatory to send logs with Promtail. -#CLUSTER_NAME= +#CLUSTER_NAME="" # Charon Cluster Peer. Mandatory to send logs with Promtail. -#CLUSTER_PEER= +#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 709ce0da..0133298c 100644 --- a/.env.sample.mainnet +++ b/.env.sample.mainnet @@ -188,13 +188,13 @@ CHARON_EXECUTION_CLIENT_RPC_ENDPOINT=http://${EL}:8545 #CHARON_LOKI_ADDRESSES= # Charon Cluster Name. Mandatory to send logs with Promtail. -#CLUSTER_NAME= +#CLUSTER_NAME="" # Charon Cluster Peer. Mandatory to send logs with Promtail. -#CLUSTER_PEER= +#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 7623b121..b9ac8294 100644 --- a/compose-monitoring.yml +++ b/compose-monitoring.yml @@ -39,19 +39,19 @@ services: - ./data/loki:/opt/loki restart: unless-stopped - promtail: + alloy: profiles: [monitoring-log-collector] - image: grafana/promtail:${PROMTAIL_VERSION:-2.8.2} + 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