Skip to content

Instantly share code, notes, and snippets.

@rafaelcgo
Created April 10, 2020 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcgo/861df19a6b0682f4b02cbd1b4e93f10e to your computer and use it in GitHub Desktop.
Save rafaelcgo/861df19a6b0682f4b02cbd1b4e93f10e to your computer and use it in GitHub Desktop.
#!/bin/bash
# From: https://github.com/heroku/heroku-buildpack-metrics/blob/master/.profile.d/heroku-metrics-daemon.sh
setup_metrics() {
# don't do anything if we don't have a metrics url.
if [[ -z "$HEROKU_METRICS_URL" ]] || [[ "${DYNO}" = run\.* ]]; then
return 0
fi
STARTTIME=$(date +%s)
BUILD_DIR=/tmp
DOWNLOAD_URL=$(curl --retry 3 -s https://agentmon-releases.s3.amazonaws.com/latest)
if [ -z "${DOWNLOAD_URL}" ]; then
echo "!!!!! Failed to find latest agentmon. Please report this as a bug. Metrics collection will be disabled this run."
return 1
fi
BASENAME=$(basename "${DOWNLOAD_URL}")
curl -L --retry 3 -s -o "${BUILD_DIR}/${BASENAME}" "${DOWNLOAD_URL}"
# Ensure the bin folder exists, if not already.
mkdir -p "${BUILD_DIR}/bin"
# Extract agentmon release
# tar --warning=no-unknown-keyword -C "${BUILD_DIR}/bin" -zxf "${BUILD_DIR}/${BASENAME}"
tar -C "${BUILD_DIR}/bin" -zxf "${BUILD_DIR}/${BASENAME}"
chmod +x "${BUILD_DIR}/bin/agentmon"
ELAPSEDTIME=$(($(date +%s) - STARTTIME))
echo "agentmon setup took ${ELAPSEDTIME} seconds"
# AGENTMON_FLAGS=("-statsd-addr=:${PORT}")
AGENTMON_FLAG="-statsd-addr=:${PORT}"
# if [[ "${AGENTMON_DEBUG}" = "true" ]]; then
# AGENTMON_FLAGS+=("-debug")
# fi
if [[ -x "${BUILD_DIR}/bin/agentmon" ]]; then
(while true; do
# ${BUILD_DIR}/bin/agentmon "${AGENTMON_FLAGS[@]}" "${HEROKU_METRICS_URL}"
${BUILD_DIR}/bin/agentmon "${AGENTMON_FLAG}" "${HEROKU_METRICS_URL}"
echo "agentmon completed with status=${?}. Restarting"
sleep 1
done) &
else
echo "No agentmon executable found. Not starting."
fi
}
setup_metrics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment