Last active
August 7, 2025 17:28
-
-
Save defanator/10367800d43f8f422453e20bbcd6e4e1 to your computer and use it in GitHub Desktop.
collect alloy support bundle from k8s deployment of grafana-k8s-monitoring helm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # vim:sw=4:ts=4:et: | |
| set -euo pipefail | |
| SELF=$(basename "$0") | |
| TS=$(TZ=UTC date "+%Y%m%d%H%M%S") | |
| DESTDIR="alloy-support-bundles" | |
| NAMESPACE="monitoring" | |
| INSTANCE="grafana-k8s-monitoring" | |
| APP="alloy" | |
| log() { | |
| printf "%s %s: %s\n" "$(date "+%Y-%m-%d %H:%M:%S %Z")" "${SELF}" "$@" | |
| } | |
| log "looking for pods in ${NAMESPACE} namespace matching app.kubernetes.io/instance==${INSTANCE},app.kubernetes.io/name==${APP}" | |
| pods=$(kubectl -n "${NAMESPACE}" get pod -l "app.kubernetes.io/instance==${INSTANCE},app.kubernetes.io/name==${APP}" -o custom-columns=":metadata.name") | |
| if [ -z "${pods}" ]; then | |
| log "no pods found for a given match" | |
| exit 1 | |
| fi | |
| declare -A pids | |
| declare -A ports | |
| teardown() { | |
| for pod in "${!pids[@]}"; do | |
| log "killing port-forward for $pod" | |
| kill "${pids[$pod]}" | |
| done | |
| } | |
| trap 'teardown' EXIT | |
| # create port-forwards | |
| startport=20001 | |
| localport=${startport} | |
| for pod in $pods; do | |
| log "creating port-forward from localhost:${localport} to ${pod}:12345" | |
| ports[$pod]=$localport | |
| kubectl -n "${NAMESPACE}" port-forward "pod/${pod}" "${ports[$pod]}:12345" & | |
| pids["${pod}"]=$! | |
| localport=$((localport + 1)) | |
| done | |
| sleep 3 | |
| # collect support bundles | |
| # https://grafana.com/docs/alloy/latest/troubleshoot/support_bundle/ | |
| mkdir -p "${DESTDIR}" | |
| declare -a curl_pids | |
| for pod in "${!ports[@]}"; do | |
| port=${ports[$pod]} | |
| url="http://localhost:${port}/-/support" | |
| outname="${DESTDIR}/${TS}-${pod}.bundle.zip" | |
| log "saving bundle from ${pod} via ${url} to ${outname}" | |
| curl -fsS -o "${outname}" "${url}" & | |
| curl_pids+=($!) | |
| done | |
| wait "${curl_pids[@]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| SELF=$(basename "$0") | |
| log() { | |
| printf "%s %s: %s\n" "$(date "+%Y-%m-%d %H:%M:%S %Z")" "${SELF}" "$@" | |
| } | |
| while true; do | |
| log "fetching..." | |
| if ${HOME}/bin/alloy-collect-bundle.sh ; then | |
| log "successful" | |
| else | |
| log "FAILED" | |
| fi | |
| log "sleeping for 900s" | |
| sleep 900 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment