处于 CrashLoopBackOff 状态的 Apigee 指标 pod

您正在查看 ApigeeApigee Hybrid 文档。
此主题没有等效的 Apigee Edge 文档。

症状

启动时,指标 pod 保持 CrashLoopBackoff 状态。 这可能会导致指标/图表中出现周期性缺口,因为 pod 会重启。 这还可能会导致与 Analytics 数据出现差异,因为缺少部分数据。

如果 Hybrid 安装生成大量指标数据,则可能会出现此问题。如果流量负载较高(导致大量底层资源,例如发出指标的 MP),或者受监控的 Apigee 资源(例如代理、目标、环境、政策等)数量较多,则可能会产生大量数据。

错误消息

使用 kubectl 查看 pod 状态时,您会看到一个或多个指标 pod 处于 CrashLoopBackoff 状态。例如:

kubectl get pods -n NAMESPACE
NAME                                              READY   STATUS            RESTARTS   AGE

apigee-metrics-default-telemetry-proxy-1a2b3c4    0/1     CrashLoopBackoff  10         10m
apigee-metrics-adapter-apigee-telemetry-a2b3c4d   0/1     CrashLoopBackoff  10         10m
...

可能的原因

原因 说明 适用的问题排查说明
指标 pod 内存不足 由于内存不足,遥测 pod 处于 CrashLoopBackoff 状态 Apigee Hybrid

原因 1

指标 Pod 内存不足 (OOM),错误原因为 OOMKilled

诊断

检查 pod 日志,以查看问题是否正在发生:

  1. 列出 pod 以获取失败的指标 pod 的 ID:
    kubectl get pods -n APIGEE_NAMESPACE -l "app in (app, proxy, collector)"
  2. 检查失败的 pod 的日志:
    kubectl -n APIGEE_NAMESPACE describe pods POD_NAME

例如:

kubectl describe -n apigee pods apigee-metrics-default-telemetry-proxy-1a2b3c4

调查输出的 apigee-prometheus-agg 部分。如果输出类似于以下内容,则表示容器反复遇到内存不足 (OOM) 情况:

Containers:
  apigee-prometheus-agg:
    Container ID:  docker://cd893dbb06c2672c41a7d6f3f7d0de4d76742e68cef70d4250bf2d5cdfcdeae6
    Image:         us.gcr.io/apigee-saas-staging-repo/thirdparty/apigee-prom-prometheus/master:v2.9.2
    Image ID:      docker-pullable://us.gcr.io/apigee-saas-staging-repo/thirdparty/apigee-prom-prometheus/master@sha256:05350e0d1a577674442046961abf56b3e883dcd82346962f9e73f00667958f6b
    Port:          19090/TCP
    Host Port:     0/TCP
    Args:
      --config.file=/etc/prometheus/agg/prometheus.yml
      --storage.tsdb.path=/prometheus/agg/
      --storage.tsdb.retention=48h
      --web.enable-admin-api
      --web.listen-address=127.0.0.1:19090
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
      Started:      Wed, 21 Oct 2020 16:53:42 +0000
      Finished:     Wed, 21 Oct 2020 16:54:28 +0000
    Ready:          False
    Restart Count:  1446
    Limits:
      cpu:     500m
      memory:  512Mi
    Requests:
      cpu:     100m
      memory:  256Mi

解决方法

  1. 使用以下命令检查当前容器限制
    kubectl -n APIGEE_NAMESPACE describe pods POD_NAME
    
  2. 使用以下属性在 overrides.yaml 文件中配置指标 pod 限制:
    metrics:
      aggregator: # The apigee-prometheus-agg container in the "proxy" pod
        resources:
          limits:
            memory: 32Gi # default: 3Gi
      app: # The apigee-prometheus-app container in the "app" pod
        resources:
          limits:
            memory: 16Gi # default: 1Gi
    
  3. 使用 helm upgrade 应用更改:
    helm upgrade telemetry apigee-telemetry/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      -f OVERRIDES_FILE
    

    如果在提高限制后仍然遇到 OOM 错误,您可以增大底层节点的大小,以允许使用更多内存。

管理运行时层面组件

必须收集的诊断信息

收集以下诊断信息,然后与 Apigee 支持团队联系:

从 Prometheus 容器收集数据以进行问题排查

为 Prometheus 容器启动端口转发。对应用 pod 和代理 pod 重复该步骤。例如:

kubectl port-forward -n apigee apigee-metrics-apigee-telemetry-app-1a2-b3c4-d5ef 8081:9090

在集群中使用以下脚本来收集数据:

#!/bin/bash

set -e

# check if jq is installed
jq --version &> /dev/null
if [ $? -ne 0 ]; then
  echo "jq not installed"
  exit 1
fi

# check if curl is installed
curl --version &> /dev/null
if [ $? -ne 0 ] ; then
  echo "curl not installed"
  exit 1
fi

# Simple check for missing arguments
if [[ $# -eq 0 ]] ; then
  echo 'No arguments provided'
  exit 1
fi

# Simple check for missing arguments
if [[ $# -ne 3 ]]; then
  echo 'Illegal number of arguments'
  exit 1
fi

FORWARDED_PORT=${1}
DEST_DIR=${2}
CASE_NUMBER=${3}
DIR_FULL_PATH=${DEST_DIR}/${CASE_NUMBER}_$(date +%Y_%m_%d_%H_%M_%S)
CURRENT_DATE=$(date +%Y-%m-%d)

# we set the default start date for query at 10 days before current date
START_DATE=$(date +%Y-%m-%d -d "10 days ago")

mkdir -pv ${DIR_FULL_PATH}

set -x
curl -s '127.0.0.1:'${FORWARDED_PORT}'/status' | tee ${DIR_FULL_PATH}/prometheus_status_$(hostname)-$(date +%Y.%m.%d_%H.%M.%S).txt
curl -s '127.0.0.1:'${FORWARDED_PORT}'/config' | tee ${DIR_FULL_PATH}/prometheus_config_$(hostname)-$(date +%Y.%m.%d_%H.%M.%S).txt
curl -s '127.0.0.1:'${FORWARDED_PORT}'/api/v1/targets' | tee ${DIR_FULL_PATH}/prometheus_targets_$(hostname)-$(date +%Y.%m.%d_%H.%M.%S).json
curl -s '127.0.0.1:'${FORWARDED_PORT}'/api/v1/status/config' | jq . | tee ${DIR_FULL_PATH}/prometheus_status_config_$(hostname)-$(date +%Y.%m.%d_%H.%M.%S).json
curl -s '127.0.0.1:'${FORWARDED_PORT}'/debug/pprof/heap' --output ${DIR_FULL_PATH}/prometheus_heap_$(date +%Y.%m.%d_%H.%M.%S).hprof
curl -s '127.0.0.1:'${FORWARDED_PORT}'/debug/pprof/heap?debug=1' | tee ${DIR_FULL_PATH}/prometheus_heap_$(date +%Y.%m.%d_%H.%M.%S).txt
curl -s '127.0.0.1:'${FORWARDED_PORT}'/debug/pprof/goroutine' --output ${DIR_FULL_PATH}/prometheus_goroutine_$(date +%Y.%m.%d_%H.%M.%S)
curl -s '127.0.0.1:'${FORWARDED_PORT}'/debug/pprof/goroutine?debug=1' | tee ${DIR_FULL_PATH}/prometheus_goroutine_$(date +%Y.%m.%d_%H.%M.%S).txt
curl -s '127.0.0.1:'${FORWARDED_PORT}'/debug/pprof/profile?seconds=10' --output ${DIR_FULL_PATH}/prometheus_profile_10_seconds_$(date +%Y.%m.%d_%H.%M.%S)
curl -s '127.0.0.1:'${FORWARDED_PORT}'/api/v1/query?query=topk(30%2C%20count%20by%20(__name__)(%7B__name__%3D~%22.%2B%22%7D))&timeout=5s&start='${START_DATE}'T00:00:00.000Z&end='${CURRENT_DATE}'T23:59:59.00Z&step=15s' | jq . | tee ${DIR_FULL_PATH}/prometheus_topk_count_by_name_$(hostname)-$(date +%Y.%m.%d_%H.%M.%S).json
curl -s '127.0.0.1:'${FORWARDED_PORT}'/api/v1/query?query=topk(30%2C%20count%20by%20(__name__%2C%20job)(%7B__name__%3D~%22.%2B%22%7D))&timeout=5s&start='${START_DATE}'T00:00:00.000Z&end='${CURRENT_DATE}'T23:59:59.00Z&step=15s' | jq . | tee ${DIR_FULL_PATH}/prometheus_topk_group_by_job_$(hostname)-$(date +%Y.%m.%d_%H.%M.%S).json
curl -s '127.0.0.1:'${FORWARDED_PORT}'/api/v1/query?query=topk(30%2C%20count%20by%20(job)(%7B__name__%3D~%22.%2B%22%7D))&timeout=5s&start='${START_DATE}'T00:00:00.000Z&end='${CURRENT_DATE}'T23:59:59.00Z&step=15s' | jq . | tee ${DIR_FULL_PATH}/prometheus_topk_job_most_timeseries_$(hostname)-$(date +%Y.%m.%d_%H.%M.%S).json
set +x

ls -latrh ${DIR_FULL_PATH}

tar -cvzf ${DIR_FULL_PATH}.tar.gz ${DIR_FULL_PATH}/

exit 0

参数:

该脚本接受三个位置参数。

  1. 端口号:设置为您转发自的端口(例如 8081)。
  2. 目录:输出文件的基本目录。
  3. 支持请求编号:支持请求编号,用于生成的文件名。

用法示例

./prometheus_gather.sh 8081 . 1510679