Skip to content

Commit

Permalink
Add script to configure metrics and log collection from a local node (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maru-ava authored Nov 5, 2024
1 parent 45b4507 commit 3d81d5b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions scripts/configure-local-metrics-collection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

set -euo pipefail

# Configures prometheus and promtail to collect metrics and logs from
# a local node.

API_PORT="${API_PORT:-9650}"

LOGS_PATH="${LOGS_PATH:-${HOME}/.avalanchego/logs}"

# Generate a uuid to uniquely identify the collected metrics
METRICS_UUID="$(uuidgen)"

echo "Configuring metrics and log collection for a local node with API port ${API_PORT} and logs path ${LOGS_PATH}"

PROMETHEUS_CONFIG_PATH="${HOME}/.tmpnet/prometheus/file_sd_configs"
PROMETHEUS_CONFIG_FILE="${PROMETHEUS_CONFIG_PATH}/local.json"
mkdir -p "${PROMETHEUS_CONFIG_PATH}"
cat > "${PROMETHEUS_CONFIG_FILE}" <<EOL
[
{
"labels": {
"network_uuid": "${METRICS_UUID}"
},
"targets": [
"127.0.0.1:${API_PORT}"
]
}
]
EOL
echo "Wrote prometheus configuration to ${PROMETHEUS_CONFIG_FILE}"

PROMTAIL_CONFIG_PATH="${HOME}/.tmpnet/promtail/file_sd_configs"
PROMTAIL_CONFIG_FILE="${PROMTAIL_CONFIG_PATH}/local.json"
mkdir -p "${PROMTAIL_CONFIG_PATH}"
cat > "${PROMTAIL_CONFIG_FILE}" <<EOL
[
{
"labels": {
"__path__": "${LOGS_PATH}/*.log",
"network_uuid": "${METRICS_UUID}"
},
"targets": [
"localhost"
]
}
]
EOL
echo "Wrote promtail configuration to ${PROMTAIL_CONFIG_FILE}"

echo "Metrics collection by prometheus can be started with ./scripts/run_prometheus.sh"
echo "Log collection by promtail can be started with ./scripts/run_promtail.sh"
echo "Grafana link: https://grafana-poc.avax-dev.network/d/kBQpRdWnk/avalanche-main-dashboard?var-filter=network_uuid%7C%3D%7C${METRICS_UUID}"

0 comments on commit 3d81d5b

Please # to comment.