HPA无法获取现有的自定义指标? [英] Hpa not fetching existing custom metric?
问题描述
我正在使用mongodb-exporter
通过prometheus
存储/查询指标.我已经设置了一个自定义指标服务器,并为此存储了值.
I'm using mongodb-exporter
for store/query the metrics via prometheus
. I have set up a custom metric server and storing values for that .
这是prometheus-exporter
和custom-metric-server
兼容的证据.
查询:
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/monitoring/pods/*/mongodb_mongod_wiredtiger_cache_bytes"
结果:
{"kind":"MetricValueList","apiVersion":"custom.metrics.k8s.io/v1beta1","metadata":{"selfLink":"/apis/custom.metrics.k8s.io/v1beta1/namespaces/monitoring/pods/%2A/mongodb_mongod_wiredtiger_cache_bytes"},"items":[{"describedObject":{"kind":"Pod","namespace":"monitoring","name":"mongo-exporter-2-prometheus-mongodb-exporter-68f95fd65d-dvptr","apiVersion":"/v1"},"metricName":"mongodb_mongod_wiredtiger_cache_bytes","timestamp":"TTTTT","value":"0"}]}
在我的情况下,当我从mongo导出器为此自定义指标创建hpa时,hpa会向我返回此错误:
In my case when I create a hpa for this custom metrics from mongo exporter, hpa return this error to me :
failed to get mongodb_mongod_wiredtiger_cache_bytes utilization: unable to get metrics for resource mongodb_mongod_wiredtiger_cache_bytes: no metrics returned from resource metrics API
我的案子的主要问题是什么?我已经检查了所有配置,并且流程看起来还不错,但是我的错误在哪里?
What is the main issue on my case ? I have checked all configs and flow is looking fine, but where is the my mistake .
帮助
谢谢:)
推荐答案
在注释中,您写道您启用了external.metrics
,但是在原始问题中,您遇到了custom.metrics
In comments you wrote that you have enabled external.metrics
, however in original question you had issues with custom.metrics
简而言之:
-
metrics
仅支持诸如CPU或内存之类的基本指标. -
custom.metrics
允许您将基本指标扩展到所有Kubernetes对象(http_requests,pod数量等). -
external.metrics
允许收集不是Kubernetes对象的指标:
metrics
supports only basic metric like CPU or Memory.custom.metrics
allows you to extend basic metrics to all Kubernetes objects (http_requests, number of pods, etc.).external.metrics
allows to gather metrics which are not Kubernetes objects:
外部指标可让您根据任何条件自动扩展群集 监控系统中可用的指标.只需提供一个指标 带有名称和选择器的代码块,如上所述,并使用外部"指标 类型而不是对象
External metrics allow you to autoscale your cluster based on any metric available in your monitoring system. Just provide a metric block with a name and selector, as above, and use the External metric type instead of Object
For more detailed description, please check this doc.
Minikube
要验证是否启用了custom.metrics
,您需要执行以下命令并检查是否可以看到任何metrics-server...
窗格.
To verify if custom.metrics
are enabled you need to execute command below and check if you can see any metrics-server...
pod.
$ kubectl get pods -n kube-system
...
metrics-server-587f876775-9qrtc 1/1 Running 4 5d1h
第二种方法是检查minikube
是否通过metrics-server
Second way is to check if minikube
have enabled metrics-server
by
$ minikube addons list
...
- metrics-server: enabled
如果已禁用,请执行
$ sudo minikube addons enable metrics-server
✅ metrics-server was successfully enabled
GKE
当前在GKE上,默认情况下打开heapster
和metrics-server
,但默认情况下不支持custom.metrics
.
您必须安装prometheus adapter
或stackdriver
.
Currently at GKE heapster
and metrics-server
are turn on as default but custom.metrics
are not supported by default.
You have to install prometheus adapter
or stackdriver
.
Kubeadm
Kubeadm开头不包含heapster
或metrics server
.为了易于安装,您可以使用此YAML .
Kubeadm do not include heapster
or metrics server
at the beginning. For easy installation, you can use this YAML.
稍后您必须安装prometheus adapter
.
应用custom.metrics
Minikube
,Kubeadm
,GKE
相同.
应用custom.metrics
的最简单方法是通过
Easiest way to apply custom.metrics
is to install prometheus adapter via Helm
.
安装头盔后,您将看到注释:
After helm installation you will be able to see note:
NOTES:
my-release-prometheus-adapter has been deployed.
In a few minutes you should be able to list metrics using the following command(s):
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1
作为其他信息,您可以使用jq
获得更多用户友好的输出.
As additional information, you can use jq
to get more user friendly output.
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 | jq .
这篇关于HPA无法获取现有的自定义指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!