【问题标题】:How to enable Ruby Language Runtime Metrics for container (stack: container) applications at Heroku如何在 Heroku 为容器(堆栈:容器)应用程序启用 Ruby 语言运行时指标
【发布时间】:2020-04-17 08:19:49
【问题描述】:

我们使用 Heroku 来托管我们的一些应用程序,并且我们希望在每个应用程序的指标仪表板中提供语言运行时指标。

我根据 Ruby 语言指标“Getting Started”一文进行了所有操作,但指标不会显示。

我的应用位于 stack: container 而不是 heroku-18 或 heroku-16 堆栈中。

他们说:

此过程不适用于基于容器的应用程序,因为它们不使用构建包。目前此测试版不支持基于容器的应用程序。

有没有办法让它工作?

【问题讨论】:

    标签: ruby heroku


    【解决方案1】:

    在与 Heroku 的支持交谈后,我们找到了一种让它发挥作用的方法。我们使用的是 Alpine docker 镜像:

    1. 我们将bash 和curl 添加到我们的Dockerfile (apk add bash curl)
    2. 我们将 heroku-metrics-daemon.sh 复制到 /etc/profile.d/,以便在 Heroku dyno 启动时作为 profile.d 脚​​本运行。
    3. 我们需要编辑.sh 文件:
      1. 我们从 tar 命令中删除了 --warning=no-unknown-keyword 标志。显然它与 Alpine tar 不兼容,只与 GNU tar 兼容。您还可以将 GNU tar 添加到您的图像中。
      2. 我们遇到了脚本中的数组解析/语法问题,即使安装了bash 和#!/bin/bash,所以我们从脚本中删除了使用AGENTMON_DEBUG 的选项。

    最终的脚本是:

    #!/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
    

    【讨论】:

      猜你喜欢
      • 2020-04-30
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多