【问题标题】:Kubernetes Prometheus metric for HPA (horizontal pod autoscaler) `currentCPUUtilizationPercentage`?HPA(水平 Pod 自动缩放器)`currentCPUUtilizationPercentage` 的 Kubernetes Prometheus 指标?
【发布时间】:2020-08-30 00:54:38
【问题描述】:

在使用 CoreOS Prometheus Operator 抓取所有标准集群指标的 Kubernetes 集群上,哪个 Prometheus 指标会显示简单 HPA(水平 pod 自动缩放器)的 currentCPUUtilizationPercentage 值?

如果我设置一个简单的 hpa,例如:

$ kubectl autoscale deployment php-apache --cpu-percent=30 --min=3 --max=10

然后,如果我这样做 kubectl get hpa php-apache -o yaml,我会看到类似:

spec:
  maxReplicas: 10
  minReplicas: 3
  targetCPUUtilizationPercentage: 30
  ...
status:
  currentCPUUtilizationPercentage: 28
  currentReplicas: 9
  desiredReplicas: 9
  ...

我想在 Prometheus 中看到 currentCPUUtilizationPercentage。我已经完成了一堆 Prometheus 查询来寻找这个。

我搜索了所有标记为 {hpa="php-apache"} 的指标,我看到了许多 hpa 指标,但没有看到我正在寻找的指标。我可以看到 kube_hpa_spec_target_metric 设置为 30,我可以看到像 kube_hpa_status_condition 这样的当前状态指标,但看不到我想要查看的当前 cpu 指标值。

我搜索了所有标记为{metric_name="cpu"} 的指标,只看到kube_hpa_spec_target_metric

我搜索了所有标记为 {container="my-container-name"}{pod=~"my-pod-prefix.*"} 的容器和 pod 相关指标,我看到了几个与 cpu 相关的指标,例如 container_cpu_usage_seconds_total abnd container_spec_cpu_quota,但没有任何类似或似乎可以使用的指标在计算我正在寻找的currentCPUUtilizationPercentage 值?

仅供参考,这是在 Kubernetes 1.17.x 上并使用最新版本的 CoreOS Prometheus Operator。

【问题讨论】:

    标签: kubernetes prometheus prometheus-operator hpa


    【解决方案1】:

    如果我没记错的话 currentCPUUtilizationPercentage 是 HPA 的 k8 内部指标,而不是直接作为指标公开,您可以使用 Prometheus 抓取。 见https://github.com/kubernetes/community/blob/master/contributors/design-proposals/autoscaling/horizontal-pod-autoscaler.md#autoscaling-algorithm

    您可能可以抓取 currentCPUUtilizationPercentage 指标的组件并创建自定义指标以在 Prometheus 中查看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      • 2022-10-04
      相关资源
      最近更新 更多